我怎么会assertThat是什么东西null?
例如
assertThat(attr.getValue(), is(""));
但是我收到一个错误,说我不能null在is(null).
您可以使用IsNull.nullValue()方法:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
为什么不使用assertNull(object)/ assertNotNull(object)?
如果你想hamcrest,你可以做
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
在Junit你可以做
import static junit.framework.Assert.assertNull;
assertNull(object);
使用以下内容(来自 Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
在 Kotlinis中是保留的,所以使用:
assertThat(attr.getValue(), `is`(nullValue()));