使用Hamcrest的断言,在一行中有多个对象?

时间:2014-09-26 07:21:14

标签: junit hamcrest

我可以使用Hamcrest的assertThat在一行代码中断言几个对象吗?对象不在集合中。例如,我想assertThat四个字符串是相等的。另外,我如何断言所有对象都为空?

2 个答案:

答案 0 :(得分:1)

使用Hamcrest的Every

assertThat(listOfStrings, Every.everyItem(CoreMatchers.equalTo("someValue"));
assertThat(listOfStrings, Every.everyItem(CoreMatchers.nullValue());

答案 1 :(得分:-1)

assertThat("All values should be equals to origin", origin, allOf(is(str1), is(str2));
assertThat("All values should be null", null, allOf(is(obj1), is(obj2));