• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.junit.rules;
2 
3 import org.junit.Rule;
4 import org.junit.runners.model.FrameworkMethod;
5 import org.junit.runners.model.Statement;
6 
7 /**
8  * A MethodRule is an alteration in how a test method is run and reported.
9  * Multiple {@link MethodRule}s can be applied to a test method. The
10  * {@link Statement} that executes the method is passed to each annotated
11  * {@link Rule} in turn, and each may return a substitute or modified
12  * {@link Statement}, which is passed to the next {@link Rule}, if any. For
13  * examples of how this can be useful, see these provided MethodRules,
14  * or write your own:
15  *
16  * <ul>
17  *   <li>{@link ErrorCollector}: collect multiple errors in one test method</li>
18  *   <li>{@link ExpectedException}: make flexible assertions about thrown exceptions</li>
19  *   <li>{@link ExternalResource}: start and stop a server, for example</li>
20  *   <li>{@link TemporaryFolder}: create fresh files, and delete after test</li>
21  *   <li>{@link TestName}: remember the test name for use during the method</li>
22  *   <li>{@link TestWatchman}: add logic at events during method execution</li>
23  *   <li>{@link Timeout}: cause test to fail after a set time</li>
24  *   <li>{@link Verifier}: fail test if object state ends up incorrect</li>
25  * </ul>
26  */
27 @Deprecated
28 public interface MethodRule {
29 	/**
30 	 * Modifies the method-running {@link Statement} to implement an additional
31 	 * test-running rule.
32 	 *
33 	 * @param base The {@link Statement} to be modified
34 	 * @param method The method to be run
35 	 * @param target The object on with the method will be run.
36 	 * @return a new statement, which may be the same as {@code base},
37 	 * a wrapper around {@code base}, or a completely new Statement.
38 	 */
apply(Statement base, FrameworkMethod method, Object target)39 	Statement apply(Statement base, FrameworkMethod method, Object target);
40 }