【问题标题】:Assert that the list is not empty - with or without Hamcrest?断言列表不为空 - 有或没有 Hamcrest?
【发布时间】:2014-01-29 14:08:57
【问题描述】:

这与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 版本是否有所收获?两者是等价的吗?

【问题讨论】:

    标签: java collections junit hamcrest


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多