类 EventPublishingTestExecutionListener
- 所有已实现的接口:
cn.taketoday.core.Ordered,TestExecutionListener
TestExecutionListener that publishes test execution events to the
ApplicationContext
for the currently executing test.
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 Infra 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.
Note that the EventPublishingTestExecutionListener is registered by
default; however, it only publishes events if the ApplicationContext
has already been loaded. This
prevents the ApplicationContext from being loaded unnecessarily or too
early. Consequently, a BeforeTestClassEvent will not be published until
after the ApplicationContext has been loaded by another
TestExecutionListener. For example, with the default set of
TestExecutionListeners registered, a BeforeTestClassEvent will
not be published for the first test class that uses a particular test
ApplicationContext, but a BeforeTestClassEvent will be published
for any subsequent test class in the same test suite that uses the same test
ApplicationContext since the context will already have been loaded
when subsequent test classes run (as long as the context has not been removed
from the ContextCache
via @DirtiesContext
or the max-size eviction policy). If you wish to ensure that a
BeforeTestClassEvent is published for every test class, you need to
register a TestExecutionListener that loads the ApplicationContext
in the beforeTestClass callback, and that TestExecutionListener must be registered
before the EventPublishingTestExecutionListener. Similarly, if
@DirtiesContext is used to remove the ApplicationContext from
the context cache after the last test method in a given test class, the
AfterTestClassEvent will not be published for that test class.
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 Framework's @Async
support. For further details, consult the class-level Javadoc for
@EventListener.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Frank Scheffler
- 另请参阅:
-
字段概要
从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidafterTestClass(TestContext testContext) voidafterTestExecution(TestContext testContext) voidafterTestMethod(TestContext testContext) voidbeforeTestClass(TestContext testContext) voidbeforeTestExecution(TestContext testContext) voidbeforeTestMethod(TestContext testContext) final intgetOrder()Returns10000.voidprepareTestInstance(TestContext testContext)
-
构造器详细资料
-
EventPublishingTestExecutionListener
public EventPublishingTestExecutionListener()
-
-
方法详细资料
-
getOrder
public final int getOrder()Returns10000.- 指定者:
getOrder在接口中cn.taketoday.core.Ordered- 覆盖:
getOrder在类中AbstractTestExecutionListener
-
beforeTestClass
- 指定者:
beforeTestClass在接口中TestExecutionListener- 覆盖:
beforeTestClass在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull
-
prepareTestInstance
- 指定者:
prepareTestInstance在接口中TestExecutionListener- 覆盖:
prepareTestInstance在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull
-
beforeTestMethod
- 指定者:
beforeTestMethod在接口中TestExecutionListener- 覆盖:
beforeTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method will be executed; nevernull- 另请参阅:
-
beforeTestExecution
- 指定者:
beforeTestExecution在接口中TestExecutionListener- 覆盖:
beforeTestExecution在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method will be executed; nevernull- 另请参阅:
-
afterTestExecution
- 指定者:
afterTestExecution在接口中TestExecutionListener- 覆盖:
afterTestExecution在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method will be executed; nevernull- 另请参阅:
-
afterTestMethod
- 指定者:
afterTestMethod在接口中TestExecutionListener- 覆盖:
afterTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method was executed; nevernull- 另请参阅:
-
afterTestClass
- 指定者:
afterTestClass在接口中TestExecutionListener- 覆盖:
afterTestClass在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull
-