Annotation Interface AfterAll
@AfterAllis used to signal that the annotated method should be executed after all tests in the current test class.
In contrast to
methods are only executed once for a given test class.
@AfterAll methods must have a
void return type, must not
private, and must be
static by default. Consequently,
@AfterAll methods are not supported in
classes or as interface default methods unless the test class is
However, beginning with Java 16
@AfterAll methods may be declared as
@Nested test classes, and the
Lifecycle.PER_CLASS restriction no longer applies.
methods may optionally declare parameters to be resolved by
Inheritance and Execution Order
@AfterAll methods are inherited from superclasses as long as
they are not hidden (default mode with
overridden, or superseded (i.e., replaced based on
signature only, irrespective of Java's visibility rules). Furthermore,
@AfterAll methods from superclasses will be executed before
@AfterAll methods in subclasses.
@AfterAll methods declared in an interface are
inherited as long as they are not hidden or overridden,
@AfterAll methods from an interface will be executed after
@AfterAll methods in the class that implements the interface.
JUnit Jupiter does not guarantee the execution order of multiple
@AfterAll methods 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.
@AfterAll methods are in no way linked to
@BeforeAll methods. Consequently, there are no guarantees with regard
to their wrapping behavior. For example, given two
createB() as well as
order in which the
@BeforeAll methods are executed (e.g.
createB()) does not imply any order for the
@AfterAll methods. In other words,
destroyA() might be called before or after
destroyB(). The JUnit Team therefore recommends that developers
declare at most one
@BeforeAll method and at most one
@AfterAll method per test class or test interface unless there are no
dependencies between the
@BeforeAll methods or between the
@AfterAll may be used as a meta-annotation in order to create
a custom composed annotation that inherits the semantics of
- See Also: