1
我有一个参数化测试,其中一个参数是布尔值,以显示测试是否通过或失败。Hamcrest条件匹配器?
在我的测试,我有以下几点:
的参数是这样的:{0, 1, true}
的测试方法包括:
if (expectedResult) {
assertThat(myList, matchesUsingMyCustomMatcher(otherList));
} else {
assertThat(myList, not(matchesUsingMyCustomMatcher(otherList.subList(start, end))));
}
什么,我不想做是写一个if-else语句。因此我的问题是:是否有条件匹配器?例如: assertThat(myList, ifMatcher(expected, matchesUsingMyCustomMatcher(otherList)));
不知道我对你的理解是否正确,但是......在数学上,“如果一个接下来的b”等价于“(不是a)或b”,那么它将使用'anyOf'与'not “匹配者? – ajb 2014-12-04 17:26:15
在http://hamcrest.org/JavaHamcrest/javadoc/1.3/中描述了一个'Condition'类。也许这就是你需要的? – ajb 2014-12-04 17:27:30
@ajb谢谢你,我会看看条件。此外,我编辑我的帖子,使其更清楚我想实现什么。 – Ibolit 2014-12-04 17:40:25