断言列表不是空的 - 有没有Hamcrest?

时间:2014-01-29 14:08:57

标签: java collections junit hamcrest

这与Checking that a List is not empty in Hamcrest

有关

我有一个问题 - 如果我们可以断言列表不是空的而不使用Hamcrest而只是使用JUnit:

assertFalse(list.isEmpty());

正在使用

assertThat(list.isEmpty(), is(false));

assertThat((Collection)list, is(not(empty())));

值得吗?

我无法理解我们在这种情况下使用Hamcrest版本获得了什么?两者都是等价的吗?

1 个答案:

答案 0 :(得分:10)

它们是相同的功能。 hamcrest提供了更像英语的可读语言和更好的错误消息。在这种简单的情况下,我可能会使用assertFalse

相关问题