• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Sometimes several tests need to share computationally expensive setup
10  * (like logging into a database). While this can compromise the independence of
11  * tests, sometimes it is a necessary optimization. Annotating a <code>public static void</code> no-arg method
12  * with <code>@BeforeClass</code> causes it to be run once before any of
13  * the test methods in the class. The <code>@BeforeClass</code> methods of superclasses
14  * will be run before those of the current class, unless they are shadowed in the current class.
15  * <p>
16  * For example:
17  * <pre>
18  * public class Example {
19  *    &#064;BeforeClass public static void onlyOnce() {
20  *       ...
21  *    }
22  *    &#064;Test public void one() {
23  *       ...
24  *    }
25  *    &#064;Test public void two() {
26  *       ...
27  *    }
28  * }
29  * </pre>
30  *
31  * @see org.junit.AfterClass
32  * @since 4.0
33  */
34 @Retention(RetentionPolicy.RUNTIME)
35 @Target(ElementType.METHOD)
36 public @interface BeforeClass {
37 }
38