程序包 org.junit.rules

类 TestWatchman

  • 所有已实现的接口:
    MethodRule

    @Deprecated
    public class TestWatchman
    extends Object
    implements MethodRule
    已过时。
    Use TestWatcher (which implements TestRule) instead.
    TestWatchman 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 MethodRule watchman= new TestWatchman() {
          @Override
          public void failed(Throwable e, FrameworkMethod method) {
              watchedLog+= method.getName() + " " + e.getClass().getSimpleName()
                      + "\n";
             }
    
          @Override
          public void succeeded(FrameworkMethod method) {
              watchedLog+= method.getName() + " " + "success!\n";
             }
         };
    
      @Test
      public void fails() {
          fail();
         }
    
      @Test
      public void succeeds() {
         }
     }
     
    从以下版本开始:
    4.7
    • 构造器详细资料

    • 方法详细资料

      • apply

        public Statement apply​(Statement base,
                               FrameworkMethod method,
                               Object target)
        已过时。
        从接口复制的说明: MethodRule
        Modifies the method-running Statement to implement an additional test-running rule.
        指定者:
        apply 在接口中 MethodRule
        参数:
        base - The Statement to be modified
        method - The method to be run
        target - The object on which the method will be run.
        返回:
        a new statement, which may be the same as base, a wrapper around base, or a completely new Statement.
      • finished

        public void finished​(FrameworkMethod method)
        已过时。
        Invoked when a test method finishes (whether passing or failing)