程序包 org.junit.rules

类 TestWatcher

  • 所有已实现的接口:
    TestRule
    直接已知子类:
    TestName

    public abstract class TestWatcher
    extends Object
    implements TestRule
    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() {
         }
     }
     
    从以下版本开始:
    4.9