程序包 org.junit
注释类型 Before
@Retention(RUNTIME) @Target(METHOD) public @interface Before
When writing tests, it is common to find that several tests need similar objects created before they can run. Annotating apublic void
method with@Before
causes that method to be run before theTest
method. The@Before
methods of superclasses will be run before those of the current class, unless they are overridden in the current class. No other ordering is defined.Here is a simple example:
public class Example { List empty; @Before public void initialize() { empty= new ArrayList(); } @Test public void size() { ... } @Test public void remove() { ... } }
- 从以下版本开始:
- 4.0
- 另请参阅:
BeforeClass
,After