我想要断言一个列表在 JUnit 4 中不为空,当我搜索时,我发现了这篇文章:Checking that a List is not empty in Hamcrest,它使用了 Hamcrest。
assertThat(result.isEmpty(), is(false));
导致我出现这个错误:
方法 is(boolean) 在类型 MaintenanceDaoImplTest 中未定义
如何在不使用 Hamcrest
的情况下完成这个操作。
assertThat(items, IsCollectionWithSize.hasSize(greaterThan(1)))
会检查集合的大小。但如果失败,它不会打印集合中的项目 :( - Ilya Serbis