@@ -1098,10 +1098,10 @@ javadoc.
1098
1098
[[spring-testing-annotation-testexecutionlisteners]]
1099
1099
===== `@TestExecutionListeners`
1100
1100
1101
- `@TestExecutionListeners` defines class-level metadata for configuring the
1102
- `TestExecutionListener` implementations that should be registered with the
1103
- `TestContextManager`. Typically, `@TestExecutionListeners` is used in conjunction with
1104
- `@ContextConfiguration` .
1101
+ `@TestExecutionListeners` is used to register listeners for a particular test class, its
1102
+ subclasses, and its nested classes. If you wish to register a listener globally, you
1103
+ should register it via the automatic discovery mechanism described in
1104
+ <<testcontext-tel-config>> .
1105
1105
1106
1106
The following example shows how to register two `TestExecutionListener` implementations:
1107
1107
@@ -1132,7 +1132,9 @@ By default, `@TestExecutionListeners` provides support for inheriting listeners
1132
1132
superclasses or enclosing classes. See
1133
1133
<<testcontext-junit-jupiter-nested-test-configuration>> and the
1134
1134
{api-spring-framework}/test/context/TestExecutionListeners.html[`@TestExecutionListeners`
1135
- javadoc] for an example and further details.
1135
+ javadoc] for an example and further details. If you discover that you need to switch
1136
+ back to using the default `TestExecutionListener` implementations, see the note
1137
+ in <<testcontext-tel-config-registering-tels>>.
1136
1138
1137
1139
[[spring-testing-annotation-recordapplicationevents]]
1138
1140
===== `@RecordApplicationEvents`
@@ -2460,12 +2462,46 @@ by default, exactly in the following order:
2460
2462
[[testcontext-tel-config-registering-tels]]
2461
2463
===== Registering `TestExecutionListener` Implementations
2462
2464
2463
- You can register `TestExecutionListener` implementations for a test class and its
2464
- subclasses by using the `@TestExecutionListeners` annotation. See
2465
+ You can register `TestExecutionListener` implementations explicitly for a test class, its
2466
+ subclasses, and its nested classes by using the `@TestExecutionListeners` annotation. See
2465
2467
<<integration-testing-annotations, annotation support>> and the javadoc for
2466
2468
{api-spring-framework}/test/context/TestExecutionListeners.html[`@TestExecutionListeners`]
2467
2469
for details and examples.
2468
2470
2471
+ .Switching to default `TestExecutionListener` implementations
2472
+ [NOTE]
2473
+ ====
2474
+ If you extend a class that is annotated with `@TestExecutionListeners` and you need to
2475
+ switch to using the default set of listeners, you can annotate your class with the
2476
+ following.
2477
+
2478
+ [source,java,indent=0,subs="verbatim,quotes",role="primary"]
2479
+ .Java
2480
+ ----
2481
+ // Switch to default listeners
2482
+ @TestExecutionListeners(
2483
+ listeners = {},
2484
+ inheritListeners = false,
2485
+ mergeMode = MERGE_WITH_DEFAULTS)
2486
+ class MyTest extends BaseTest {
2487
+ // class body...
2488
+ }
2489
+ ----
2490
+
2491
+ [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
2492
+ .Kotlin
2493
+ ----
2494
+ // Switch to default listeners
2495
+ @TestExecutionListeners(
2496
+ listeners = [],
2497
+ inheritListeners = false,
2498
+ mergeMode = MERGE_WITH_DEFAULTS)
2499
+ class MyTest : BaseTest {
2500
+ // class body...
2501
+ }
2502
+ ----
2503
+ ====
2504
+
2469
2505
[[testcontext-tel-config-automatic-discovery]]
2470
2506
===== Automatic Discovery of Default `TestExecutionListener` Implementations
2471
2507
0 commit comments