Annotation Interface BeforeSuite
@BeforeSuite is used to signal that the annotated method should be
executed before all tests in the current test suite.
Method Signatures
@BeforeSuite methods must have a void return type, must
be static and must not be private.
Inheritance and Execution Order
@BeforeSuite methods are inherited from superclasses as long as they
are not overridden according to the visibility rules of the Java
language. Furthermore, @BeforeSuite methods from superclasses will be
executed before @BeforeSuite methods in subclasses.
The JUnit Platform Suite Engine does not guarantee the execution order of
multiple @BeforeSuite 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.
In addition, @BeforeSuite methods are in no way linked to
@AfterSuite methods. Consequently, there are no guarantees with regard
to their wrapping behavior. For example, given two
@BeforeSuite methods createA() and createB() as well as
two @AfterSuite methods destroyA() and destroyB(), the
order in which the @BeforeSuite methods are executed (e.g.
createA() before createB()) does not imply any order for the
seemingly corresponding @AfterSuite methods. In other words,
destroyA() might be called before or after
destroyB(). The JUnit Team therefore recommends that developers
declare at most one @BeforeSuite method and at most one
@AfterSuite method per test class or test interface unless there are no
dependencies between the @BeforeSuite methods or between the
@AfterSuite methods.
Composition
@BeforeSuite may be used as a meta-annotation in order to create
a custom composed annotation that inherits the semantics of
@BeforeSuite.
- Since:
- 1.11
- See Also: