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  * <p>If you allocate expensive external resources in a {@link org.junit.BeforeClass} method you need to release them
     10  * after all the tests in the class have run. Annotating a <code>public static void</code> method
     11  * with <code>&#064;AfterClass</code> causes that method to be run after all the tests in the class have been run. All <code>&#064;AfterClass</code>
     12  * methods are guaranteed to run even if a {@link org.junit.BeforeClass} method throws an
     13  * exception. The <code>&#064;AfterClass</code> methods declared in superclasses will be run after those of the current
     14  * class.</p>
     15  *
     16  * Here is a simple example:
     17 * <pre>
     18  * public class Example {
     19  *    private static DatabaseConnection database;
     20  *    &#064;BeforeClass public static void login() {
     21  *          database= ...;
     22  *    }
     23  *    &#064;Test public void something() {
     24  *          ...
     25  *    }
     26  *    &#064;Test public void somethingElse() {
     27  *          ...
     28  *    }
     29  *    &#064;AfterClass public static void logout() {
     30  *          database.logout();
     31  *    }
     32  * }
     33  * </pre>
     34  *
     35  * @see org.junit.BeforeClass
     36  * @see org.junit.Test
     37  */
     38 @Retention(RetentionPolicy.RUNTIME)
     39 @Target(ElementType.METHOD)
     40 public @interface AfterClass {
     41 }
     42