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

© . This site is unofficial and not affiliated with VMware.