@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
test class configuration 和 @TestExecutionListeners
javadoc。如果您發現需要切換回使用預設的 TestExecutionListener
實現,請參閱 註冊 TestExecutionListener
實現 中的說明。