diff --git a/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java index fcc7b08b4c..7b08f832be 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/EventPublishingTestExecutionListener.java @@ -18,6 +18,7 @@ package org.springframework.test.context.event; import org.springframework.core.Ordered; import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.support.AbstractTestExecutionListener; /** @@ -25,10 +26,6 @@ import org.springframework.test.context.support.AbstractTestExecutionListener; * that publishes test lifecycle events to a Spring test * {@link org.springframework.context.ApplicationContext ApplicationContext}. * - *
These events may be consumed for various reasons, such as resetting mock - * beans or tracing test execution. Since these events may be consumed by regular - * Spring beans, they can be shared among different test classes. - * *
These events may be consumed for various reasons, such as resetting mock + * beans or tracing test execution. One advantage of consuming test events rather + * than implementing a custom {@link TestExecutionListener} is that test events + * may be consumed by any Spring bean registered in the test {@code ApplicationContext}, + * and such beans may benefit directly from dependency injection and other features + * of the {@code ApplicationContext}. In contrast, a {@link TestExecutionListener} + * is not a bean in the {@code ApplicationContext}. + * + *
By default, if a test event listener throws an exception while consuming + * a test event, that exception will propagate to the underlying testing framework + * in use. For example, if the consumption of a {@code BeforeTestMethodEvent} + * results in an exception, the corresponding test method will fail as a result + * of the exception. In contrast, if an asynchronous test event listener throws + * an exception, the exception will not propagate to the underlying testing framework. + * For further details on asynchronous exception handling, consult the class-level + * Javadoc for {@link org.springframework.context.event.EventListener @EventListener}. + * + *
If you want a particular test event listener to process events asynchronously, + * you can use Spring's {@link org.springframework.scheduling.annotation.Async @Async} + * support. For further details, consult the class-level Javadoc for + * {@link org.springframework.context.event.EventListener @EventListener}. + * *
Note that this {@code TestExecutionListener} is not registered by default, * but it may be registered for a given test class via