Skip to content

Commit 2ecea3b

Browse files
committed
Document semantics for a disabled test regarding class-level callbacks
Closes #3649
1 parent 6f06cb2 commit 2ecea3b

18 files changed

+135
-69
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.11.0-M1.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ repository on GitHub.
5151
==== New Features and Improvements
5252

5353
* `JAVA_23` has been added to the `JRE` enum for use with JRE-based execution conditions.
54+
* Improved documentation for semantics of a disabled test regarding class-level lifecycle
55+
methods and callbacks.
5456
* New `@AutoClose` annotation that can be applied to fields within tests to automatically
5557
close the annotated resource after test execution. See the
5658
<<../user-guide/index.adoc#writing-tests-built-in-extensions-AutoClose, User Guide>> for

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ annotation, via one of the annotations discussed in
358358
<<writing-tests-conditional-execution>>, or via a custom <<extensions-conditions,
359359
`ExecutionCondition`>>.
360360

361+
When `@Disabled` is applied at the class level, all test methods within that class are
362+
automatically disabled as well.
363+
364+
If a test method is disabled via `@Disabled`, that prevents execution of the test method
365+
and method-level lifecycle callbacks such as `@BeforeEach` methods, `@AfterEach` methods,
366+
and corresponding extension APIs. However, that does not prevent the test class from being
367+
instantiated, and it does not prevent the execution of class-level lifecycle callbacks
368+
such as `@BeforeAll` methods, `@AfterAll` methods, and corresponding extension APIs.
369+
361370
Here's a `@Disabled` test class.
362371

363372
[source,java,indent=0]
@@ -393,17 +402,26 @@ superclass is `@Disabled`, you must redeclare `@Disabled` on the subclass.
393402
=== Conditional Test Execution
394403

395404
The <<extensions-conditions, `ExecutionCondition`>> extension API in JUnit Jupiter allows
396-
developers to either _enable_ or _disable_ a container or test based on certain
405+
developers to either _enable_ or _disable_ a test class or test method based on certain
397406
conditions _programmatically_. The simplest example of such a condition is the built-in
398407
`{DisabledCondition}` which supports the `{Disabled}` annotation (see
399-
<<writing-tests-disabling>>). In addition to `@Disabled`, JUnit Jupiter also supports
400-
several other annotation-based conditions in the `org.junit.jupiter.api.condition`
401-
package that allow developers to enable or disable containers and tests _declaratively_.
402-
When multiple `ExecutionCondition` extensions are registered, a container or test is
403-
disabled as soon as one of the conditions returns _disabled_. If you wish to provide
408+
<<writing-tests-disabling>>).
409+
410+
In addition to `@Disabled`, JUnit Jupiter also supports several other annotation-based
411+
conditions in the `org.junit.jupiter.api.condition` package that allow developers to
412+
enable or disable test classes and test methods _declaratively_. If you wish to provide
404413
details about why they might be disabled, every annotation associated with these built-in
405414
conditions has a `disabledReason` attribute available for that purpose.
406415

416+
When multiple `ExecutionCondition` extensions are registered, a test class or test method
417+
is disabled as soon as one of the conditions returns _disabled_. If a test class is
418+
disabled, all test methods within that class are automatically disabled as well. If a test
419+
method is disabled, that prevents execution of the test method and method-level lifecycle
420+
callbacks such as `@BeforeEach` methods, `@AfterEach` methods, and corresponding extension
421+
APIs. However, that does not prevent the test class from being instantiated, and it does
422+
not prevent the execution of class-level lifecycle callbacks such as `@BeforeAll` methods,
423+
`@AfterAll` methods, and corresponding extension APIs.
424+
407425
See <<extensions-conditions, `ExecutionCondition`>> and the following sections for
408426
details.
409427

junit-jupiter-api/src/main/java/org/junit/jupiter/api/Disabled.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
* Consequently, if you wish to apply the same semantics to a subclass, this
3535
* annotation must be redeclared on the subclass.
3636
*
37-
* <p>When applied at the method level, the presence of this annotation does not
38-
* prevent the test class from being instantiated. Rather, it prevents the
39-
* execution of the test method and method-level lifecycle callbacks such as
37+
* <p>If a test method is disabled via this annotation, that prevents execution
38+
* of the test method and method-level lifecycle callbacks such as
4039
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
41-
* extension APIs.
40+
* extension APIs. However, that does not prevent the test class from being
41+
* instantiated, and it does not prevent the execution of class-level lifecycle
42+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
43+
* corresponding extension APIs.
4244
*
4345
* @since 5.0
4446
* @see #value

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledForJreRange.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
* Consequently, if you wish to apply the same semantics to a subclass, this
3434
* annotation must be redeclared on the subclass.
3535
*
36-
* <p>If a test method is disabled via this annotation, that does not prevent
37-
* the test class from being instantiated. Rather, it prevents the execution of
38-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
39-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
36+
* <p>If a test method is disabled via this annotation, that prevents execution
37+
* of the test method and method-level lifecycle callbacks such as
38+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
39+
* extension APIs. However, that does not prevent the test class from being
40+
* instantiated, and it does not prevent the execution of class-level lifecycle
41+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
42+
* corresponding extension APIs.
4043
*
4144
* <p>This annotation may be used as a meta-annotation in order to create a
4245
* custom <em>composed annotation</em> that inherits the semantics of this

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledIf.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
* Consequently, if you wish to apply the same semantics to a subclass, this
3434
* annotation must be redeclared on the subclass.
3535
*
36-
* <p>If a test method is disabled via this annotation, that does not prevent
37-
* the test class from being instantiated. Rather, it prevents the execution of
38-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
39-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
36+
* <p>If a test method is disabled via this annotation, that prevents execution
37+
* of the test method and method-level lifecycle callbacks such as
38+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
39+
* extension APIs. However, that does not prevent the test class from being
40+
* instantiated, and it does not prevent the execution of class-level lifecycle
41+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
42+
* corresponding extension APIs.
4043
*
4144
* <p>This annotation may be used as a meta-annotation in order to create a
4245
* custom <em>composed annotation</em> that inherits the semantics of this

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledIfEnvironmentVariable.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
* Consequently, if you wish to apply the same semantics to a subclass, this
3636
* annotation must be redeclared on the subclass.
3737
*
38-
* <p>If a test method is disabled via this annotation, that does not prevent
39-
* the test class from being instantiated. Rather, it prevents the execution of
40-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
41-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
38+
* <p>If a test method is disabled via this annotation, that prevents execution
39+
* of the test method and method-level lifecycle callbacks such as
40+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
41+
* extension APIs. However, that does not prevent the test class from being
42+
* instantiated, and it does not prevent the execution of class-level lifecycle
43+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
44+
* corresponding extension APIs.
4245
*
4346
* <p>If the specified environment variable is undefined, the presence of this
4447
* annotation will have no effect on whether or not the class or method

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledIfSystemProperty.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
* Consequently, if you wish to apply the same semantics to a subclass, this
3636
* annotation must be redeclared on the subclass.
3737
*
38-
* <p>If a test method is disabled via this annotation, that does not prevent
39-
* the test class from being instantiated. Rather, it prevents the execution of
40-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
41-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
38+
* <p>If a test method is disabled via this annotation, that prevents execution
39+
* of the test method and method-level lifecycle callbacks such as
40+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
41+
* extension APIs. However, that does not prevent the test class from being
42+
* instantiated, and it does not prevent the execution of class-level lifecycle
43+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
44+
* corresponding extension APIs.
4245
*
4346
* <p>If the specified system property is undefined, the presence of this
4447
* annotation will have no effect on whether or not the class or method

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledInNativeImage.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232
* Consequently, if you wish to apply the same semantics to a subclass, this
3333
* annotation must be redeclared on the subclass.
3434
*
35-
* <p>If a test method is disabled via this annotation, that does not prevent
36-
* the test class from being instantiated. Rather, it prevents the execution of
37-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
38-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
35+
* <p>If a test method is disabled via this annotation, that prevents execution
36+
* of the test method and method-level lifecycle callbacks such as
37+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
38+
* extension APIs. However, that does not prevent the test class from being
39+
* instantiated, and it does not prevent the execution of class-level lifecycle
40+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
41+
* corresponding extension APIs.
3942
*
4043
* <p>This annotation may be used as a meta-annotation in order to create a
4144
* custom <em>composed annotation</em> that inherits the semantics of this

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnJre.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
* Consequently, if you wish to apply the same semantics to a subclass, this
3434
* annotation must be redeclared on the subclass.
3535
*
36-
* <p>If a test method is disabled via this annotation, that does not prevent
37-
* the test class from being instantiated. Rather, it prevents the execution of
38-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
39-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
36+
* <p>If a test method is disabled via this annotation, that prevents execution
37+
* of the test method and method-level lifecycle callbacks such as
38+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
39+
* extension APIs. However, that does not prevent the test class from being
40+
* instantiated, and it does not prevent the execution of class-level lifecycle
41+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
42+
* corresponding extension APIs.
4043
*
4144
* <p>This annotation may be used as a meta-annotation in order to create a
4245
* custom <em>composed annotation</em> that inherits the semantics of this

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/DisabledOnOs.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
* Consequently, if you wish to apply the same semantics to a subclass, this
3939
* annotation must be redeclared on the subclass.
4040
*
41-
* <p>If a test method is disabled via this annotation, that does not prevent
42-
* the test class from being instantiated. Rather, it prevents the execution of
43-
* the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
44-
* methods, {@code @AfterEach} methods, and corresponding extension APIs.
41+
* <p>If a test method is disabled via this annotation, that prevents execution
42+
* of the test method and method-level lifecycle callbacks such as
43+
* {@code @BeforeEach} methods, {@code @AfterEach} methods, and corresponding
44+
* extension APIs. However, that does not prevent the test class from being
45+
* instantiated, and it does not prevent the execution of class-level lifecycle
46+
* callbacks such as {@code @BeforeAll} methods, {@code @AfterAll} methods, and
47+
* corresponding extension APIs.
4548
*
4649
* <p>This annotation may be used as a meta-annotation in order to create a
4750
* custom <em>composed annotation</em> that inherits the semantics of this

0 commit comments

Comments
 (0)