All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.rules.TestWatchman Maven / Gradle / Ivy

Go to download

Statistical sampling library for use in virtualdataset libraries, based on apache commons math 4

There is a newer version: 2.12.15
Show newest version
package org.junit.rules;

import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

/**
 * 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 * @deprecated Use {@link TestWatcher} (which implements {@link TestRule}) instead. */ @Deprecated public class TestWatchman implements MethodRule { public Statement apply(final Statement base, final FrameworkMethod method, Object target) { return new Statement() { @Override public void evaluate() throws Throwable { starting(method); try { base.evaluate(); succeeded(method); } catch (AssumptionViolatedException e) { throw e; } catch (Throwable e) { failed(e, method); throw e; } finally { finished(method); } } }; } /** * Invoked when a test method succeeds */ public void succeeded(FrameworkMethod method) { } /** * Invoked when a test method fails */ public void failed(Throwable e, FrameworkMethod method) { } /** * Invoked when a test method is about to start */ public void starting(FrameworkMethod method) { } /** * Invoked when a test method finishes (whether passing or failing) */ public void finished(FrameworkMethod method) { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy