How is assertThat
something is null
例如
assertThat(attr.getValue(), is(""));
但是我收到一个错误,告诉我在is(null)
中不能有null
。
发布于 2013-09-25 01:00:45
您可以使用IsNull.nullValue()
方法:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
发布于 2013-09-25 01:00:12
为什么不使用assertNull(object)
/ assertNotNull(object)
?
发布于 2013-09-25 01:04:39
如果你想使用hamcrest
,你可以这样做
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
在Junit
中,您可以
import static junit.framework.Assert.assertNull;
assertNull(object);
https://stackoverflow.com/questions/18987692
复制相似问题