| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.junit.rules.TestWatcher
public abstract class TestWatcher
TestWatcher is a base class for Rules that take note of the testing action, without modifying it. For example, this class will keep a log of each passing and failing test:
 public static class WatchmanTest {
  private static String watchedLog;
  @Rule
  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() {
     }
 }
 
| Constructor Summary | |
|---|---|
| TestWatcher() | |
| Method Summary | |
|---|---|
|  Statement | apply(Statement base,
      Description description)Modifies the method-running Statementto 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 | skipped(org.junit.internal.AssumptionViolatedException e,
        Description description)Invoked when a test is skipped due to a failed assumption. | 
| protected  void | starting(Description description)Invoked when a test is about to start | 
| protected  void | succeeded(Description description)Invoked when a test succeeds | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public TestWatcher()
| Method Detail | 
|---|
public Statement apply(Statement base,
                       Description description)
TestRuleStatement to implement this
 test-running rule.
apply in interface TestRulebase - 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)
protected void failed(Throwable e,
                      Description description)
protected void skipped(org.junit.internal.AssumptionViolatedException e,
                       Description description)
protected void starting(Description description)
protected void finished(Description description)
| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||