Class TestWatchman

  • All Implemented Interfaces:
    MethodRule

    @Deprecated
    public class TestWatchman
    extends java.lang.Object
    implements MethodRule
    Deprecated.
    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() {
         }
     }
     
    Since:
    4.7
    • Method Detail

      • apply

        public Statement apply​(Statement base,
                               FrameworkMethod method,
                               java.lang.Object target)
        Deprecated.
        Description copied from interface: MethodRule
        Modifies the method-running Statement to implement an additional test-running rule.
        Specified by:
        apply in interface MethodRule
        Parameters:
        base - The Statement to be modified
        method - The method to be run
        target - The object on which the method will be run.
        Returns:
        a new statement, which may be the same as base, a wrapper around base, or a completely new Statement.
      • failed

        public void failed​(java.lang.Throwable e,
                           FrameworkMethod method)
        Deprecated.
        Invoked when a test method fails
      • starting

        public void starting​(FrameworkMethod method)
        Deprecated.
        Invoked when a test method is about to start
      • finished

        public void finished​(FrameworkMethod method)
        Deprecated.
        Invoked when a test method finishes (whether passing or failing)