Home | History | Annotate | Download | only in junit
      1 package org.junit;
      2 
      3 import java.lang.annotation.ElementType;
      4 import java.lang.annotation.Retention;
      5 import java.lang.annotation.RetentionPolicy;
      6 import java.lang.annotation.Target;
      7 
      8 /**
      9  * Annotates fields that contain rules. Such a field must be public, not
     10  * static, and a subtype of {@link org.junit.rules.TestRule}.
     11  * The {@link org.junit.runners.model.Statement} passed
     12  * to the {@link org.junit.rules.TestRule} will run any {@link Before} methods,
     13  * then the {@link Test} method, and finally any {@link After} methods,
     14  * throwing an exception if any of these fail.  If there are multiple
     15  * annotated {@link Rule}s on a class, they will be applied in an order
     16  * that depends on your JVM's implementation of the reflection API, which is
     17  * undefined, in general.
     18  *
     19  * For example, here is a test class that creates a temporary folder before
     20  * each test method, and deletes it after each:
     21  *
     22  * <pre>
     23  * public static class HasTempFolder {
     24  * 	&#064;Rule
     25  * 	public TemporaryFolder folder= new TemporaryFolder();
     26  *
     27  * 	&#064;Test
     28  * 	public void testUsingTempFolder() throws IOException {
     29  * 		File createdFile= folder.newFile(&quot;myfile.txt&quot;);
     30  * 		File createdFolder= folder.newFolder(&quot;subfolder&quot;);
     31  * 		// ...
     32  * 	}
     33  * }
     34  * </pre>
     35  *
     36  * For more information and more examples, see
     37  * {@link org.junit.rules.TestRule}.
     38  *
     39  * Note: for backwards compatibility, this annotation may also mark
     40  * fields of type {@link org.junit.rules.MethodRule}, which will be honored.  However,
     41  * this is a deprecated interface and feature.
     42  */
     43 @Retention(RetentionPolicy.RUNTIME)
     44 @Target({ElementType.FIELD})
     45 public @interface Rule {
     46 
     47 }