此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
@TestExecutionListeners
@TestExecutionListeners
用于为特定测试类注册侦听器,则其
子类及其嵌套类。如果您希望全局注册侦听器,请
应通过TestExecutionListener
配置.
以下示例显示了如何注册两个TestExecutionListener
实现:
-
Java
-
Kotlin
@ContextConfiguration
@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class}) (1)
class CustomTestExecutionListenerTests {
// class body...
}
1 | 注册 2TestExecutionListener 实现。 |
@ContextConfiguration
@TestExecutionListeners(CustomTestExecutionListener::class, AnotherTestExecutionListener::class) (1)
class CustomTestExecutionListenerTests {
// class body...
}
1 | 注册 2TestExecutionListener 实现。 |
默认情况下,@TestExecutionListeners
支持从
超类或封闭类。看@Nested
test 类配置和@TestExecutionListeners
Javadoc有关示例和更多详细信息。如果您发现需要切换
回到使用默认的TestExecutionListener
implementations,请参阅注释
在注册TestExecutionListener
实现.