Skip to content

Commit 67c5f40

Browse files
committed
#2914: explain 'superseding' for lifecycle methods in user guide
1 parent a2381a6 commit 67c5f40

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

documentation/src/docs/asciidoc/user-guide/extensions.adoc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,27 +799,31 @@ callbacks implemented by `Extension2`. `Extension1` is therefore said to _wrap_
799799
JUnit Jupiter also guarantees _wrapping_ behavior within class and interface hierarchies
800800
for user-supplied _lifecycle methods_ (see <<writing-tests-classes-and-methods>>).
801801

802-
* `@BeforeAll` methods are inherited from superclasses as long as they are not _hidden_ or
803-
_overridden_. Furthermore, `@BeforeAll` methods from superclasses will be executed
804-
**before** `@BeforeAll` methods in subclasses.
802+
* `@BeforeAll` methods are inherited from superclasses as long as they are not _hidden_, or
803+
_overridden_, or _superseded_ (i.e., replaced based on signature only, irrespective of
804+
Java's visibility rules). Furthermore, `@BeforeAll` methods from superclasses will be
805+
executed **before** `@BeforeAll` methods in subclasses.
805806
** Similarly, `@BeforeAll` methods declared in an interface are inherited as long as they
806807
are not _hidden_ or _overridden_, and `@BeforeAll` methods from an interface will be
807808
executed **before** `@BeforeAll` methods in the class that implements the interface.
808-
* `@AfterAll` methods are inherited from superclasses as long as they are not _hidden_ or
809-
_overridden_. Furthermore, `@AfterAll` methods from superclasses will be executed
810-
**after** `@AfterAll` methods in subclasses.
809+
* `@AfterAll` methods are inherited from superclasses as long as they are not _hidden_, or
810+
_overridden_, or _superseded_ (i.e., replaced based on signature only, irrespective of
811+
Java's visibility rules). Furthermore, `@AfterAll` methods from superclasses will be
812+
executed **after** `@AfterAll` methods in subclasses.
811813
** Similarly, `@AfterAll` methods declared in an interface are inherited as long as they
812814
are not _hidden_ or _overridden_, and `@AfterAll` methods from an interface will be
813815
executed **after** `@AfterAll` methods in the class that implements the interface.
814816
* `@BeforeEach` methods are inherited from superclasses as long as they are not
815-
_overridden_. Furthermore, `@BeforeEach` methods from superclasses will be executed
816-
**before** `@BeforeEach` methods in subclasses.
817+
_overridden_ or _superseded_ (i.e., replaced based on signature only, irrespective of
818+
Java's visibility rules). Furthermore, `@BeforeEach` methods from superclasses will be
819+
executed **before** `@BeforeEach` methods in subclasses.
817820
** Similarly, `@BeforeEach` methods declared as interface default methods are inherited as
818821
long as they are not _overridden_, and `@BeforeEach` default methods will be executed
819822
**before** `@BeforeEach` methods in the class that implements the interface.
820823
* `@AfterEach` methods are inherited from superclasses as long as they are not
821-
_overridden_. Furthermore, `@AfterEach` methods from superclasses will be executed
822-
**after** `@AfterEach` methods in subclasses.
824+
_overridden_ or _superseded_ (i.e., replaced based on signature only, irrespective of
825+
Java's visibility rules). Furthermore, `@AfterEach` methods from superclasses will be
826+
executed **after** `@AfterEach` methods in subclasses.
823827
** Similarly, `@AfterEach` methods declared as interface default methods are inherited as
824828
long as they are not _overridden_, and `@AfterEach` default methods will be executed
825829
**after** `@AfterEach` methods in the class that implements the interface.

documentation/src/docs/asciidoc/user-guide/writing-tests.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ in the `junit-jupiter-api` module.
3434
| `@TestInstance` | Used to configure the <<writing-tests-test-instance-lifecycle, test instance lifecycle>> for the annotated test class. Such annotations are _inherited_.
3535
| `@DisplayName` | Declares a custom <<writing-tests-display-names,display name>> for the test class or test method. Such annotations are not _inherited_.
3636
| `@DisplayNameGeneration` | Declares a custom <<writing-tests-display-name-generator,display name generator>> for the test class. Such annotations are _inherited_.
37-
| `@BeforeEach` | Denotes that the annotated method should be executed _before_ *each* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, or `@TestFactory` method in the current class; analogous to JUnit 4's `@Before`. Such methods are _inherited_ unless they are _overridden_.
38-
| `@AfterEach` | Denotes that the annotated method should be executed _after_ *each* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, or `@TestFactory` method in the current class; analogous to JUnit 4's `@After`. Such methods are _inherited_ unless they are _overridden_.
39-
| `@BeforeAll` | Denotes that the annotated method should be executed _before_ *all* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, and `@TestFactory` methods in the current class; analogous to JUnit 4's `@BeforeClass`. Such methods are _inherited_ (unless they are _hidden_ or _overridden_) and must be `static` (unless the "per-class" <<writing-tests-test-instance-lifecycle, test instance lifecycle>> is used).
40-
| `@AfterAll` | Denotes that the annotated method should be executed _after_ *all* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, and `@TestFactory` methods in the current class; analogous to JUnit 4's `@AfterClass`. Such methods are _inherited_ (unless they are _hidden_ or _overridden_) and must be `static` (unless the "per-class" <<writing-tests-test-instance-lifecycle, test instance lifecycle>> is used).
37+
| `@BeforeEach` | Denotes that the annotated method should be executed _before_ *each* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, or `@TestFactory` method in the current class; analogous to JUnit 4's `@Before`. Such methods are _inherited_ unless they are _overridden_ or _superseded_ (i.e., replaced based on signature only, irrespective of Java's visibility rules).
38+
| `@AfterEach` | Denotes that the annotated method should be executed _after_ *each* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, or `@TestFactory` method in the current class; analogous to JUnit 4's `@After`. Such methods are _inherited_ unless they are _overridden_ or _superseded_ (i.e., replaced based on signature only, irrespective of Java's visibility rules).
39+
| `@BeforeAll` | Denotes that the annotated method should be executed _before_ *all* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, and `@TestFactory` methods in the current class; analogous to JUnit 4's `@BeforeClass`. Such methods are _inherited_ (unless they are _hidden_, or _overridden_, or _superseded_, i.e., replaced based on signature only, irrespective of Java's visibility rules) and must be `static` (unless the "per-class" <<writing-tests-test-instance-lifecycle, test instance lifecycle>> is used).
40+
| `@AfterAll` | Denotes that the annotated method should be executed _after_ *all* `@Test`, `@RepeatedTest`, `@ParameterizedTest`, and `@TestFactory` methods in the current class; analogous to JUnit 4's `@AfterClass`. Such methods are _inherited_ (unless they are _hidden_, or _overridden_, or _superseded_, i.e., replaced based on signature only, irrespective of Java's visibility rules) and must be `static` (unless the "per-class" <<writing-tests-test-instance-lifecycle, test instance lifecycle>> is used).
4141
| `@Nested` | Denotes that the annotated class is a non-static <<writing-tests-nested,nested test class>>. On Java 8 through Java 15, `@BeforeAll` and `@AfterAll` methods cannot be used directly in a `@Nested` test class unless the "per-class" <<writing-tests-test-instance-lifecycle, test instance lifecycle>> is used. Beginning with Java 16, `@BeforeAll` and `@AfterAll` methods can be declared as `static` in a `@Nested` test class with either test instance lifecycle mode. Such annotations are not _inherited_.
4242
| `@Tag` | Used to declare <<writing-tests-tagging-and-filtering,tags for filtering tests>>, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are _inherited_ at the class level but not at the method level.
4343
| `@Disabled` | Used to <<writing-tests-disabling,disable>> a test class or test method; analogous to JUnit 4's `@Ignore`. Such annotations are not _inherited_.

0 commit comments

Comments
 (0)