|
38 | 38 | * methods may optionally declare parameters to be resolved by
|
39 | 39 | * {@link org.junit.jupiter.api.extension.ParameterResolver ParameterResolvers}.
|
40 | 40 | *
|
41 |
| - * <h3>Inheritance</h3> |
| 41 | + * <h3>Inheritance and Execution Order</h3> |
42 | 42 | *
|
43 | 43 | * <p>{@code @BeforeAll} methods are inherited from superclasses as long as
|
44 | 44 | * they are not <em>hidden</em> or <em>overridden</em>. Furthermore,
|
|
50 | 50 | * and {@code @BeforeAll} methods from an interface will be executed before
|
51 | 51 | * {@code @BeforeAll} methods in the class that implements the interface.
|
52 | 52 | *
|
| 53 | + * <p>JUnit Jupiter does not guarantee the execution order of multiple |
| 54 | + * {@code @BeforeAll} methods that are declared within a single test class or |
| 55 | + * test interface. While it may at times appear that these methods are invoked |
| 56 | + * in alphabetical order, they are in fact sorted using an algorithm that is |
| 57 | + * deterministic but intentionally non-obvious. |
| 58 | + * |
| 59 | + * <p>In addition, {@code @BeforeAll} methods are in no way linked to |
| 60 | + * {@code @AfterAll} methods, i.e. there are no guarantees with regard to their |
| 61 | + * wrapping behavior. For example, given two {@code @BeforeAll} methods |
| 62 | + * {@code createA()} and {@code createB()} as well as two {@code @AfterAll} |
| 63 | + * methods {@code destroyA()} and {@code destroyB()}, the order in which the |
| 64 | + * {@code @BeforeAll} methods are executed (e.g. {@code createA()} before |
| 65 | + * {@code createB()}) does not imply any order for the seemingly corresponding |
| 66 | + * {@code @AfterAll} methods: (e.g. {@code destroyA()} might be called before |
| 67 | + * <em>or</em> after {@code destroyB()}). Thus, the JUnit Team recommends that |
| 68 | + * developers declare at most one {@code @BeforeAll}/{@code @AfterAll} method |
| 69 | + * per test class/interface unless there are no dependencies between them. |
| 70 | + * |
53 | 71 | * <h3>Composition</h3>
|
54 | 72 | *
|
55 | 73 | * <p>{@code @BeforeAll} may be used as a meta-annotation in order to create
|
|
0 commit comments