Annotation Type AfterAll
-
@Target({ANNOTATION_TYPE,METHOD}) @Retention(RUNTIME) @Documented @API(status=STABLE, since="5.0") public @interface AfterAll@AfterAllis used to signal that the annotated method should be executed after all tests in the current test class.In contrast to
@AfterEachmethods,@AfterAllmethods are only executed once for a given test class.Method Signatures
@AfterAllmethods must have avoidreturn type, must not beprivate, and must bestaticby default. Consequently,@AfterAllmethods are not supported in@Nestedtest classes or as interface default methods unless the test class is annotated with@TestInstance(Lifecycle.PER_CLASS).@AfterAllmethods may optionally declare parameters to be resolved byParameterResolvers.Inheritance and Execution Order
@AfterAllmethods are inherited from superclasses as long as they are not hidden or overridden. Furthermore,@AfterAllmethods from superclasses will be executed after@AfterAllmethods in subclasses.Similarly,
@AfterAllmethods declared in an interface are inherited as long as they are not hidden or overridden, and@AfterAllmethods from an interface will be executed after@AfterAllmethods in the class that implements the interface.JUnit Jupiter does not guarantee the execution order of multiple
@AfterAllmethods that are declared within a single test class or test interface. While it may at times appear that these methods are invoked in alphabetical order, they are in fact sorted using an algorithm that is deterministic but intentionally non-obvious.In addition,
@AfterAllmethods are in no way linked to@BeforeAllmethods. Consequently, there are no guarantees with regard to their wrapping behavior. For example, given two@BeforeAllmethodscreateA()andcreateB()as well as two@AfterAllmethodsdestroyA()anddestroyB(), the order in which the@BeforeAllmethods are executed (e.g.createA()beforecreateB()) does not imply any order for the seemingly corresponding@AfterAllmethods. In other words,destroyA()might be called before or afterdestroyB(). The JUnit Team therefore recommends that developers declare at most one@BeforeAllmethod and at most one@AfterAllmethod per test class or test interface unless there are no dependencies between the@BeforeAllmethods or between the@AfterAllmethods.Composition
@AfterAllmay be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of@AfterAll.- Since:
- 5.0
- See Also:
BeforeAll,BeforeEach,AfterEach,Test,TestFactory,TestInstance