public abstract class TestWatcher extends Object implements TestRule
public static class WatchmanTest { private static String watchedLog; @Rule public MethodRule watchman= new TestWatcher() { @Override protected void failed(Description d) { watchedLog+= d + "\n"; } @Override protected void succeeded(Description d) { watchedLog+= d + " " + "success!\n"; } }; @Test public void fails() { fail(); } @Test public void succeeds() { } }
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(Throwable e,
Description description)
Invoked when a test fails
|
protected void |
finished(Description description)
Invoked when a test method finishes (whether passing or failing)
|
protected void |
starting(Description description)
Invoked when a test is about to start
|
protected void |
succeeded(Description description)
Invoked when a test succeeds
|
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.protected void succeeded(Description description)
description
- protected void failed(Throwable e, Description description)
e
- description
- protected void starting(Description description)
description
- protected void finished(Description description)
description
-