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