001 package org.junit; 002 003 import java.lang.annotation.ElementType; 004 import java.lang.annotation.Retention; 005 import java.lang.annotation.RetentionPolicy; 006 import java.lang.annotation.Target; 007 008 /** 009 * When writing tests, it is common to find that several tests need similar 010 * objects created before they can run. Annotating a <code>public void</code> method 011 * with <code>@Before</code> causes that method to be run before the {@link org.junit.Test} method. 012 * The <code>@Before</code> methods of superclasses will be run before those of the current class, 013 * unless they are overridden in the current class. No other ordering is defined. 014 * <p> 015 * Here is a simple example: 016 * <pre> 017 * public class Example { 018 * List empty; 019 * @Before public void initialize() { 020 * empty= new ArrayList(); 021 * } 022 * @Test public void size() { 023 * ... 024 * } 025 * @Test public void remove() { 026 * ... 027 * } 028 * } 029 * </pre> 030 * 031 * @see org.junit.BeforeClass 032 * @see org.junit.After 033 * @since 4.0 034 */ 035 @Retention(RetentionPolicy.RUNTIME) 036 @Target(ElementType.METHOD) 037 public @interface Before { 038 } 039