public class EventPublishingTestExecutionListener extends AbstractTestExecutionListener
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.
BeforeTestClassEvent
PrepareTestInstanceEvent
BeforeTestMethodEvent
BeforeTestExecutionEvent
AfterTestExecutionEvent
AfterTestMethodEvent
AfterTestClassEvent
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
.
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
.
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
.
@BeforeTestClass
,
@PrepareTestInstance
,
@BeforeTestMethod
,
@BeforeTestExecution
,
@AfterTestExecution
,
@AfterTestMethod
,
@AfterTestClass
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
EventPublishingTestExecutionListener() |
Modifier and Type | Method and Description |
---|---|
void |
afterTestClass(TestContext testContext)
|
void |
afterTestExecution(TestContext testContext)
|
void |
afterTestMethod(TestContext testContext)
|
void |
beforeTestClass(TestContext testContext)
|
void |
beforeTestExecution(TestContext testContext)
|
void |
beforeTestMethod(TestContext testContext)
|
int |
getOrder()
Returns
10000 . |
void |
prepareTestInstance(TestContext testContext)
|
public EventPublishingTestExecutionListener()
public final int getOrder()
10000
.getOrder
in interface Ordered
getOrder
in class AbstractTestExecutionListener
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
public void beforeTestClass(TestContext testContext)
beforeTestClass
in interface TestExecutionListener
beforeTestClass
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null
public void prepareTestInstance(TestContext testContext)
prepareTestInstance
in interface TestExecutionListener
prepareTestInstance
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null
public void beforeTestMethod(TestContext testContext)
beforeTestMethod
in interface TestExecutionListener
beforeTestMethod
in class AbstractTestExecutionListener
testContext
- the test context in which the test method will be
executed; never null
TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void beforeTestExecution(TestContext testContext)
beforeTestExecution
in interface TestExecutionListener
beforeTestExecution
in class AbstractTestExecutionListener
testContext
- the test context in which the test method will be
executed; never null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void afterTestExecution(TestContext testContext)
afterTestExecution
in interface TestExecutionListener
afterTestExecution
in class AbstractTestExecutionListener
testContext
- the test context in which the test method will be
executed; never null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
public void afterTestMethod(TestContext testContext)
afterTestMethod
in interface TestExecutionListener
afterTestMethod
in class AbstractTestExecutionListener
testContext
- the test context in which the test method was
executed; never null
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,
TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
,
TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
public void afterTestClass(TestContext testContext)
afterTestClass
in interface TestExecutionListener
afterTestClass
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null