当我尝试给出原因以防匹配器与值不匹配时,我会遇到编译错误。
@Rule
public ErrorCollector collector = new ErrorCollector();
@Test
public void textShouldMatch(){
String expected ="Lebron James";
String result ="Kobe Bryant";
collector.checkThat("Doesn't match",result, is(expected));
}
javadoc 具有以下用于 checkThat 方法的语法:
checkThat
public <T> void checkThat(String reason,T value, Matcher<T> matcher)
如果匹配器与值不匹配,则将具有给定原因的失败添加到表中。继续执行,但如果匹配失败,测试将在最后失败。