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  * 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  * unless they are overridden in the current class. No other ordering is defined.
     14  * <p>
     15  * Here is a simple example:
     16  * <pre>
     17  * public class Example {
     18  *    List empty;
     19  *    &#064;Before public void initialize() {
     20  *       empty= new ArrayList();
     21  *    }
     22  *    &#064;Test public void size() {
     23  *       ...
     24  *    }
     25  *    &#064;Test public void remove() {
     26  *       ...
     27  *    }
     28  * }
     29  * </pre>
     30  *
     31  * @see org.junit.BeforeClass
     32  * @see org.junit.After
     33  * @since 4.0
     34  */
     35 @Retention(RetentionPolicy.RUNTIME)
     36 @Target(ElementType.METHOD)
     37 public @interface Before {
     38 }
     39 
     40