Google Truth.assertThat.contains 的行为与 List.contains 不同

问题描述 投票:0回答:1

使用

List.containsAll()
Truth.assertThat(list).contains(originalList)
的行为有所不同。

按预期工作

assertThat(getItemsByChannelId.containsAll(entitiesChannelAPage2)).isTrue()

未按预期工作

assertThat(getItemsByChannelId).contains(entitiesChannelAPage2)

我正在尝试验证从本地数据库查询返回的数据类列表是否与执行某些删除后先前插入的项目相同。我在这里缺少什么或者第一种方法是此类验证的理想解决方案吗?我希望能够最大限度地利用 Truth 的 API,特别是获得有意义的错误消息,而不是晦涩难懂的

expected to be true

android unit-testing assertion instrumented-test google-truth
1个回答
0
投票

由于您想要一个与

List.containsAll
类似的断言,听起来您可能想要...

assertThat(getItemsByChannelId).containsAtLeastElementsIn(entitiesChannelAPage2)

...而不是...

assertThat(getItemsByChannelId).contains(entitiesChannelAPage2)
© www.soinside.com 2019 - 2024. All rights reserved.