ErrorCollector 规则允许在发现第一个问题后继续执行测试(例如,收集表中所有不正确的行,并一次报告它们)。
我尝试将 org.junit.rules.ErrorCollector 与 Jbehave 故事一起使用,但在执行后,JBehave 说“所有测试都通过了”,即使有一些失败并且 ErrorCollector() 收集了它们。JBehave 应该说某些步骤失败了。
在 JUnit 中没关系:
public static class UsesErrorCollectorTwice {
@Rule
public ErrorCollector collector= new ErrorCollector();
@Test
public void example() {
String x = [..]
collector.checkThat(x, not(containsString("a")));
collector.checkThat(y, containsString("b"));
}
}
但是在jbehave中:
Scenario: S-1
Given check something
……
@Given("check something")
public void checkLoggedIn() {
loginSteps.check_that();
}
……
import org.hamcrest.Matchers;
import org.junit.rules.ErrorCollector;
import org.junit.Rule;
……
@Rule
public ErrorCollector collector= new ErrorCollector();
……
@Step
public void check_that() {
collector.checkThat("Error example", navigationMenuPanel.isUserSignedIn(), Matchers.is(false));
collector.checkThat("User has not been logged-in yet!", navigationMenuPanel.isUserSignedIn(), Matchers.is(true));
collector.addError(new Throwable("Shit error happen"));
collector.checkThat("It'wrong", 1, Matchers.equalTo(3));
}
这个故事总是过去了。