public abstract class TestWatcher extends java.lang.Object implements TestRule
public static class WatchmanTest { private static String watchedLog; @Rule(order = Integer.MIN_VALUE) public TestWatcher watchman= new TestWatcher() { @Override protected void failed(Throwable e, Description description) { watchedLog+= description + "\n"; } @Override protected void succeeded(Description description) { watchedLog+= description + " " + "success!\n"; } }; @Test public void fails() { fail(); } @Test public void succeeds() { } }
It is recommended to always set the order
of the
TestWatcher
to Integer.MIN_VALUE
so that it encloses all
other rules. Otherwise it may see failed tests as successful and vice versa
if some rule changes the result of a test (e.g. ErrorCollector
or
ExpectedException
).
Constructor and Description |
---|
TestWatcher() |
Modifier and Type | Method and Description |
---|---|
Statement |
apply(Statement base,
Description description)
Modifies the method-running
Statement to implement this
test-running rule. |
protected void |
failed(java.lang.Throwable e,
Description description)
Invoked when a test fails
|
private void |
failedQuietly(java.lang.Throwable e,
Description description,
java.util.List<java.lang.Throwable> errors) |
protected void |
finished(Description description)
Invoked when a test method finishes (whether passing or failing)
|
private void |
finishedQuietly(Description description,
java.util.List<java.lang.Throwable> errors) |
protected void |
skipped(AssumptionViolatedException e,
Description description)
Invoked when a test is skipped due to a failed assumption.
|
protected void |
skipped(AssumptionViolatedException e,
Description description)
Deprecated.
|
private void |
skippedQuietly(AssumptionViolatedException e,
Description description,
java.util.List<java.lang.Throwable> errors) |
protected void |
starting(Description description)
Invoked when a test is about to start
|
private void |
startingQuietly(Description description,
java.util.List<java.lang.Throwable> errors) |
protected void |
succeeded(Description description)
Invoked when a test succeeds
|
private void |
succeededQuietly(Description description,
java.util.List<java.lang.Throwable> errors) |
public Statement apply(Statement base, Description description)
TestRule
Statement
to implement this
test-running rule.apply
in interface TestRule
base
- The Statement
to be modifieddescription
- A Description
of the test implemented in base
base
,
a wrapper around base
, or a completely new Statement.private void succeededQuietly(Description description, java.util.List<java.lang.Throwable> errors)
private void failedQuietly(java.lang.Throwable e, Description description, java.util.List<java.lang.Throwable> errors)
private void skippedQuietly(AssumptionViolatedException e, Description description, java.util.List<java.lang.Throwable> errors)
private void startingQuietly(Description description, java.util.List<java.lang.Throwable> errors)
private void finishedQuietly(Description description, java.util.List<java.lang.Throwable> errors)
protected void succeeded(Description description)
protected void failed(java.lang.Throwable e, Description description)
protected void skipped(AssumptionViolatedException e, Description description)
@Deprecated protected void skipped(AssumptionViolatedException e, Description description)
skipped(AssumptionViolatedException, Description)
protected void starting(Description description)
protected void finished(Description description)