类 EventPublishingTestExecutionListener
- java.lang.Object
- org.springframework.test.context.support.AbstractTestExecutionListener
- org.springframework.test.context.event.EventPublishingTestExecutionListener
- 所有已实现的接口:
Ordered
,TestExecutionListener
public class EventPublishingTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener
that publishes test execution events to theApplicationContext
for the currently executing test. Events are only published if theApplicationContext
has already been loaded.Supported Events
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 testApplicationContext
, and such beans may benefit directly from dependency injection and other features of theApplicationContext
. In contrast, aTestExecutionListener
is not a bean in theApplicationContext
.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
.- 从以下版本开始:
- 5.2
- 作者:
- Sam Brannen, Frank Scheffler
- 另请参阅:
@BeforeTestClass
,@PrepareTestInstance
,@BeforeTestMethod
,@BeforeTestExecution
,@AfterTestExecution
,@AfterTestMethod
,@AfterTestClass
字段概要
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 EventPublishingTestExecutionListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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()
Returns10000
.void
prepareTestInstance(TestContext testContext)
构造器详细资料
EventPublishingTestExecutionListener
public EventPublishingTestExecutionListener()
方法详细资料
getOrder
public final int getOrder()
Returns10000
.- 指定者:
getOrder
在接口中Ordered
- 覆盖:
getOrder
在类中AbstractTestExecutionListener
- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
beforeTestClass
public void beforeTestClass(TestContext testContext)
- 指定者:
beforeTestClass
在接口中TestExecutionListener
- 覆盖:
beforeTestClass
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context for the test; nevernull
prepareTestInstance
public void prepareTestInstance(TestContext testContext)
- 指定者:
prepareTestInstance
在接口中TestExecutionListener
- 覆盖:
prepareTestInstance
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context for the test; nevernull
beforeTestMethod
public void beforeTestMethod(TestContext testContext)
- 指定者:
beforeTestMethod
在接口中TestExecutionListener
- 覆盖:
beforeTestMethod
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method will be executed; nevernull
- 另请参阅:
TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
,TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
beforeTestExecution
public void beforeTestExecution(TestContext testContext)
- 指定者:
beforeTestExecution
在接口中TestExecutionListener
- 覆盖:
beforeTestExecution
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method will be executed; nevernull
- 另请参阅:
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
afterTestExecution
public void afterTestExecution(TestContext testContext)
- 指定者:
afterTestExecution
在接口中TestExecutionListener
- 覆盖:
afterTestExecution
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method will be executed; nevernull
- 另请参阅:
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
afterTestMethod
public void afterTestMethod(TestContext testContext)
- 指定者:
afterTestMethod
在接口中TestExecutionListener
- 覆盖:
afterTestMethod
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method was executed; nevernull
- 另请参阅:
TestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
,TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)
,TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)
afterTestClass
public void afterTestClass(TestContext testContext)
- 指定者:
afterTestClass
在接口中TestExecutionListener
- 覆盖:
afterTestClass
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context for the test; nevernull