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>@Before</code> causes that method to be run before the {@link org.junit.Test} method. 12 * The <code>@Before</code> methods of superclasses will be run before those of the current class.</p> 13 * 14 * Here is a simple example: 15 * <pre> 16 * public class Example { 17 * List empty; 18 * @Before public void initialize() { 19 * empty= new ArrayList(); 20 * } 21 * @Test public void size() { 22 * ... 23 * } 24 * @Test public void remove() { 25 * ... 26 * } 27 * } 28 * </pre> 29 * 30 * @see org.junit.BeforeClass 31 * @see org.junit.After 32 */ 33 @Retention(RetentionPolicy.RUNTIME) 34 @Target(ElementType.METHOD) 35 public @interface Before { 36 } 37 38