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  * <p>When writing tests, it is common to find that several tests need similar
     10  * objects created before they can run. Annotating a <code>public void</code> method
     11  * with <code>&#064;Before</code> causes that method to be run before the {@link org.junit.Test} method.
     12  * The <code>&#064;Before</code> methods of superclasses will be run before those of the current class.
     13  * No other ordering is defined.
     14  * </p>
     15  *
     16  * Here is a simple example:
     17  * <pre>
     18  * public class Example {
     19  *    List empty;
     20  *    &#064;Before public void initialize() {
     21  *       empty= new ArrayList();
     22  *    }
     23  *    &#064;Test public void size() {
     24  *       ...
     25  *    }
     26  *    &#064;Test public void remove() {
     27  *       ...
     28  *    }
     29  * }
     30  * </pre>
     31  *
     32  * @see org.junit.BeforeClass
     33  * @see org.junit.After
     34  */
     35 @Retention(RetentionPolicy.RUNTIME)
     36 @Target(ElementType.METHOD)
     37 public @interface Before {
     38 }
     39 
     40