Class EventPublishingTestExecutionListener
- All Implemented Interfaces:
Ordered,TestExecutionListener
TestExecutionListener
that publishes test execution events to the
ApplicationContext
for the currently executing test. Events are only published if the
ApplicationContext has already been loaded.
Supported Events
BeforeTestClassEventPrepareTestInstanceEventBeforeTestMethodEventBeforeTestExecutionEventAfterTestExecutionEventAfterTestMethodEventAfterTestClassEvent
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 TestExecutionListener is that test events
may be consumed by any Spring bean registered in the test ApplicationContext,
and such beans may benefit directly from dependency injection and other features
of the ApplicationContext. In contrast, a TestExecutionListener
is not a bean in the ApplicationContext.
Exception Handling
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 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 @EventListener.
Asynchronous Listeners
If you want a particular test event listener to process events asynchronously,
you can use Spring's @Async
support. For further details, consult the class-level Javadoc for
@EventListener.
- Since:
- 5.2
- Author:
- Sam Brannen, Frank Scheffler
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTestClass(TestContext testContext) voidafterTestExecution(TestContext testContext) voidafterTestMethod(TestContext testContext) voidbeforeTestClass(TestContext testContext) voidbeforeTestExecution(TestContext testContext) voidbeforeTestMethod(TestContext testContext) final intgetOrder()Returns10000.voidprepareTestInstance(TestContext testContext)
-
Constructor Details
-
EventPublishingTestExecutionListener
public EventPublishingTestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns10000.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstractTestExecutionListener- Returns:
- the order value
- See Also:
-
beforeTestClass
- Specified by:
beforeTestClassin interfaceTestExecutionListener- Overrides:
beforeTestClassin classAbstractTestExecutionListener- Parameters:
testContext- the test context for the test; nevernull
-
prepareTestInstance
- Specified by:
prepareTestInstancein interfaceTestExecutionListener- Overrides:
prepareTestInstancein classAbstractTestExecutionListener- Parameters:
testContext- the test context for the test; nevernull
-
beforeTestMethod
- Specified by:
beforeTestMethodin interfaceTestExecutionListener- Overrides:
beforeTestMethodin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- See Also:
-
beforeTestExecution
- Specified by:
beforeTestExecutionin interfaceTestExecutionListener- Overrides:
beforeTestExecutionin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- See Also:
-
afterTestExecution
- Specified by:
afterTestExecutionin interfaceTestExecutionListener- Overrides:
afterTestExecutionin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- See Also:
-
afterTestMethod
- Specified by:
afterTestMethodin interfaceTestExecutionListener- Overrides:
afterTestMethodin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method was executed; nevernull- See Also:
-
afterTestClass
- Specified by:
afterTestClassin interfaceTestExecutionListener- Overrides:
afterTestClassin classAbstractTestExecutionListener- Parameters:
testContext- the test context for the test; nevernull
-