Package org.junit
Annotation Type After
@Retention(RUNTIME) @Target(METHOD) public @interface After
If you allocate external resources in aBeforemethod you need to release them after the test runs. Annotating apublic voidmethod with@Aftercauses that method to be run after theTestmethod. All@Aftermethods are guaranteed to run even if aBeforeorTestmethod throws an exception. The@Aftermethods declared in superclasses will be run after those of the current class, unless they are overridden in the current class.Here is a simple example:
public class Example { File output; @Before public void createOutputFile() { output= new File(...); } @Test public void something() { ... } @After public void deleteOutputFile() { output.delete(); } }