@TestExecutionListeners
@TestExecutionListeners 用于为带有注解的测试类、其子类及嵌套类注册监听器。如需全局注册监听器,您应通过TestExecutionListener 配置中描述的自动发现机制进行注册。
以下示例展示了如何注册两个TestExecutionListener实现:
-
Java
-
Kotlin
@ContextConfiguration
@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class}) (1)
class CustomTestExecutionListenerTests {
// class body...
}
| 1 | 注册两个TestExecutionListener实现。 |
@ContextConfiguration
@TestExecutionListeners(CustomTestExecutionListener::class, AnotherTestExecutionListener::class) (1)
class CustomTestExecutionListenerTests {
// class body...
}
| 1 | 注册两个TestExecutionListener实现。 |
默认情况下,@TestExecutionListeners 提供了从超类或封闭类继承监听器的支持。请参阅
@Nested 测试类配置 和
@TestExecutionListeners
javadoc 以获取示例和更多详细信息。如果您发现需要切换回使用默认的 TestExecutionListener 实现,请参阅
注册 TestExecutionListener 实现 中的说明。