【发布时间】:2019-03-14 16:44:28
【问题描述】:
您好,我正在编写一个单元测试,我需要断言一个列表以特定顺序包含多个类的对象。我想使用 hamcrest 来做到这一点。
现在我断言它就像 -
assertThat(actual, hasItem(isA(A.class)));
assertThat(actual, hasItem(isA(B.class)));
assertThat(actual, hasItem(isA(C.class)));
这里我想测试一下这些项目的顺序是 A->B->C。我试过这样写 -
assertThat(actual, contains(isA(A.class), isA(B.class), isA(C.class)));
但这不受支持,有没有办法使用 hamcrest 匹配器来实现这一点?
【问题讨论】:
-
您使用的是哪个版本? 1.3 版似乎对我有用。
标签: java unit-testing junit assert hamcrest