使用用于Java的hamcrest库,可以执行以下操作的一种很好的可读方式:
assertThat(someCollection, hasItem(someItem))
我要确保其中someCollection不包含任何项目someItem
使用用于Java的hamcrest库,可以执行以下操作的一种很好的可读方式:
assertThat(someCollection, hasItem(someItem))
我要确保其中someCollection不包含任何项目someItem
Answers:
否定hasItem断言
assertThat(someCollection, not(hasItem(someItem)))
Matcherzs定义了所有的。工厂方法,因此您可以进行单个*静态导入。如果没有其他人在下一个小时内张贴该行,我将查找工作。
import static org.hamcrest.MatcherAssert.assertThat;以及import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not)后,它运行良好。