Package org.junit
Annotation Type AfterClass
-
@Retention(RUNTIME) @Target(METHOD) public @interface AfterClassIf you allocate expensive external resources in aBeforeClassmethod you need to release them after all the tests in the class have run. Annotating apublic static voidmethod with@AfterClasscauses that method to be run after all the tests in the class have been run. All@AfterClassmethods are guaranteed to run even if aBeforeClassmethod throws an exception. The@AfterClassmethods declared in superclasses will be run after those of the current class, unless they are shadowed in the current class.Here is a simple example:
public class Example { private static DatabaseConnection database; @BeforeClass public static void login() { database= ...; } @Test public void something() { ... } @Test public void somethingElse() { ... } @AfterClass public static void logout() { database.logout(); } }- Since:
- 4.0
- See Also:
BeforeClass,Test