如何断言与Hamcrest什么是空的?
我将如何assertThat什么是null ?
例如
assertThat(attr.getValue(), is(""));
但是我得到一个错误,说我不能在null 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()));
- Assert.AreEqual如何确定两个genericsIEnumerables之间的相等性?
- 在MiniTest的assert_raises / must_raise中检查exception消息的期望语法是什么?
- SQLselect列表中的布尔expression式
- python的devise:为什么要声明一个声明而不是一个函数?
- Java断言关键字做什么,什么时候使用?
- 在Ruby的Kernel类中增加一个assert()方法是否是惯用的Ruby?
- 什么是static_assert做什么,你会使用它?
- AssertContains在jUnit中的string
- C# – Assert()方法是做什么的? 它仍然有用吗?