@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实现中的注意事项。