我可以使用Hamcrest的assertThat
在一行代码中断言几个对象吗?对象不在集合中。例如,我想assertThat
四个字符串是相等的。另外,我如何断言所有对象都为空?
答案 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));