Skip to content

Commit 5922642

Browse files
committed
Document exception handling and async support for test events
This commit updates the class-level Javadoc for EventPublishingTestExecutionListener in order to provide explicit documentation for exception handling and async support. See gh-18490
1 parent 2e63c66 commit 5922642

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818

1919
import org.springframework.core.Ordered;
2020
import org.springframework.test.context.TestContext;
21+
import org.springframework.test.context.TestExecutionListener;
2122
import org.springframework.test.context.support.AbstractTestExecutionListener;
2223

2324
/**
2425
* {@link org.springframework.test.context.TestExecutionListener TestExecutionListener}
2526
* that publishes test lifecycle events to a Spring test
2627
* {@link org.springframework.context.ApplicationContext ApplicationContext}.
2728
*
28-
* <p>These events may be consumed for various reasons, such as resetting <em>mock</em>
29-
* beans or tracing test execution. Since these events may be consumed by regular
30-
* Spring beans, they can be shared among different test classes.
31-
*
3229
* <h3>Supported Events</h3>
3330
* <ul>
3431
* <li>{@link BeforeTestClassEvent}</li>
@@ -40,6 +37,30 @@
4037
* <li>{@link AfterTestClassEvent}</li>
4138
* </ul>
4239
*
40+
* <p>These events may be consumed for various reasons, such as resetting <em>mock</em>
41+
* beans or tracing test execution. One advantage of consuming test events rather
42+
* than implementing a custom {@link TestExecutionListener} is that test events
43+
* may be consumed by any Spring bean registered in the test {@code ApplicationContext},
44+
* and such beans may benefit directly from dependency injection and other features
45+
* of the {@code ApplicationContext}. In contrast, a {@link TestExecutionListener}
46+
* is not a bean in the {@code ApplicationContext}.
47+
*
48+
* <h3>Exception Handling</h3>
49+
* <p>By default, if a test event listener throws an exception while consuming
50+
* a test event, that exception will propagate to the underlying testing framework
51+
* in use. For example, if the consumption of a {@code BeforeTestMethodEvent}
52+
* results in an exception, the corresponding test method will fail as a result
53+
* of the exception. In contrast, if an asynchronous test event listener throws
54+
* an exception, the exception will not propagate to the underlying testing framework.
55+
* For further details on asynchronous exception handling, consult the class-level
56+
* Javadoc for {@link org.springframework.context.event.EventListener @EventListener}.
57+
*
58+
* <h3>Asynchronous Listeners</h3>
59+
* <p>If you want a particular test event listener to process events asynchronously,
60+
* you can use Spring's {@link org.springframework.scheduling.annotation.Async @Async}
61+
* support. For further details, consult the class-level Javadoc for
62+
* {@link org.springframework.context.event.EventListener @EventListener}.
63+
*
4364
* <h3>Listener Registration</h3>
4465
* <p>Note that this {@code TestExecutionListener} is not registered by default,
4566
* but it may be registered for a given test class via

0 commit comments

Comments
 (0)