use*_*419 134 java assert hamcrest
我怎么assertThat
样null
?
例如
assertThat(attr.getValue(), is(""));
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,说我不能null
进去is(null)
.
Roh*_*ain 241
你可以使用IsNull.nullValue()
方法:
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
Run Code Online (Sandbox Code Playgroud)
Che*_*tya 28
为什么不用assertNull(object)
/ assertNotNull(object)
?
Saj*_*ran 14
如果你愿意hamcrest
,你可以做到
import static org.hamcrest.Matchers.nullValue;
assertThat(attr.getValue(), is(nullValue()));
Run Code Online (Sandbox Code Playgroud)
在Junit
你能做到的
import static junit.framework.Assert.assertNull;
assertNull(object);
Run Code Online (Sandbox Code Playgroud)
使用以下(来自Hamcrest):
assertThat(attr.getValue(), is(nullValue()));
Run Code Online (Sandbox Code Playgroud)