程序包 org.junit.rules
类 ErrorCollector
- java.lang.Object
- org.junit.rules.Verifier
- org.junit.rules.ErrorCollector
- 所有已实现的接口:
TestRule
public class ErrorCollector extends Verifier
The ErrorCollector rule allows execution of a test to continue after the first problem is found (for example, to collect _all_ the incorrect rows in a table, and report them all at once):public static class UsesErrorCollectorTwice { @Rule public ErrorCollector collector= new ErrorCollector(); @Test public void example() { collector.addError(new Throwable("first thing went wrong")); collector.addError(new Throwable("second thing went wrong")); collector.checkThat(getResult(), not(containsString("ERROR!"))); // all lines will run, and then a combined failure logged at the end. } }
- 从以下版本开始:
- 4.7
构造器概要
构造器 构造器 说明 ErrorCollector()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addError(Throwable error)
Adds a Throwable to the table.<T> T
checkSucceeds(Callable<T> callable)
Adds to the table the exception, if any, thrown fromcallable
.<T> void
checkThat(String reason, T value, Matcher<T> matcher)
Adds a failure with the givenreason
to the table ifmatcher
does not matchvalue
.<T> void
checkThat(T value, Matcher<T> matcher)
Adds a failure to the table ifmatcher
does not matchvalue
.protected void
verify()
Override this to add verification logic.
构造器详细资料
ErrorCollector
public ErrorCollector()
方法详细资料
verify
protected void verify() throws Throwable
从类复制的说明:Verifier
Override this to add verification logic. Overrides should throw an exception to indicate that verification failed.
addError
public void addError(Throwable error)
Adds a Throwable to the table. Execution continues, but the test will fail at the end.
checkThat
public <T> void checkThat(T value, Matcher<T> matcher)
Adds a failure to the table ifmatcher
does not matchvalue
. Execution continues, but the test will fail at the end if the match fails.
checkThat
public <T> void checkThat(String reason, T value, Matcher<T> matcher)
Adds a failure with the givenreason
to the table ifmatcher
does not matchvalue
. Execution continues, but the test will fail at the end if the match fails.
checkSucceeds
public <T> T checkSucceeds(Callable<T> callable)
Adds to the table the exception, if any, thrown fromcallable
. Execution continues, but the test will fail at the end ifcallable
threw an exception.