Package org.junit.rules
Class ErrorCollector
java.lang.Object
org.junit.rules.Verifier
org.junit.rules.ErrorCollector
- All Implemented Interfaces:
TestRule
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.
}
}
- Since:
- 4.7
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a Throwable to the table.<T> TcheckSucceeds(Callable<T> callable) Adds to the table the exception, if any, thrown fromcallable.<T> voidAdds a failure with the givenreasonto the table ifmatcherdoes not matchvalue.<T> voidcheckThat(T value, org.hamcrest.Matcher<T> matcher) Adds a failure to the table ifmatcherdoes not matchvalue.voidcheckThrows(Class<? extends Throwable> expectedThrowable, ThrowingRunnable runnable) Adds a failure to the table ifrunnabledoes not throw an exception of typeexpectedThrowablewhen executed.protected voidverify()Override this to add verification logic.
-
Field Details
-
errors
-
-
Constructor Details
-
ErrorCollector
public ErrorCollector()
-
-
Method Details
-
verify
Description copied from class:VerifierOverride this to add verification logic. Overrides should throw an exception to indicate that verification failed. -
addError
Adds a Throwable to the table. Execution continues, but the test will fail at the end. -
checkThat
public <T> void checkThat(T value, org.hamcrest.Matcher<T> matcher) Adds a failure to the table ifmatcherdoes not matchvalue. Execution continues, but the test will fail at the end if the match fails. -
checkThat
Adds a failure with the givenreasonto the table ifmatcherdoes not matchvalue. Execution continues, but the test will fail at the end if the match fails. -
checkSucceeds
Adds to the table the exception, if any, thrown fromcallable. Execution continues, but the test will fail at the end ifcallablethrew an exception. -
checkThrows
Adds a failure to the table ifrunnabledoes not throw an exception of typeexpectedThrowablewhen executed. Execution continues, but the test will fail at the end if the runnable does not throw an exception, or if it throws a different exception.- Parameters:
expectedThrowable- the expected type of the exceptionrunnable- a function that is expected to throw an exception when executed- Since:
- 4.13
-