|
18 | 18 |
|
19 | 19 | import org.springframework.core.Ordered;
|
20 | 20 | import org.springframework.test.context.TestContext;
|
| 21 | +import org.springframework.test.context.TestExecutionListener; |
21 | 22 | import org.springframework.test.context.support.AbstractTestExecutionListener;
|
22 | 23 |
|
23 | 24 | /**
|
24 | 25 | * {@link org.springframework.test.context.TestExecutionListener TestExecutionListener}
|
25 | 26 | * that publishes test lifecycle events to a Spring test
|
26 | 27 | * {@link org.springframework.context.ApplicationContext ApplicationContext}.
|
27 | 28 | *
|
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 |
| - * |
32 | 29 | * <h3>Supported Events</h3>
|
33 | 30 | * <ul>
|
34 | 31 | * <li>{@link BeforeTestClassEvent}</li>
|
|
40 | 37 | * <li>{@link AfterTestClassEvent}</li>
|
41 | 38 | * </ul>
|
42 | 39 | *
|
| 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 | + * |
43 | 64 | * <h3>Listener Registration</h3>
|
44 | 65 | * <p>Note that this {@code TestExecutionListener} is not registered by default,
|
45 | 66 | * but it may be registered for a given test class via
|
|
0 commit comments