此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0spring-doc.cadn.net.cn

@TestExecutionListeners

@TestExecutionListeners用于为特定测试类注册侦听器,则其 子类及其嵌套类。如果您希望全局注册侦听器,请 应通过TestExecutionListener配置.spring-doc.cadn.net.cn

以下示例显示了如何注册两个TestExecutionListener实现:spring-doc.cadn.net.cn

@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支持从 超类或封闭类。看@Nestedtest 类配置@TestExecutionListenersJavadoc有关示例和更多详细信息。如果您发现需要切换 回到使用默认的TestExecutionListenerimplementations,请参阅注释 在注册TestExecutionListener实现.spring-doc.cadn.net.cn