@TestExecutionListeners
@TestExecutionListeners
用于为带注释的测试类、其子类及其嵌套类注册侦听器。如果您希望全局注册侦听器,您应该通过TestExecutionListener
Configuration 中描述的自动发现机制进行注册。
@TestExecutionListeners
is used to register listeners for the annotated test class, its
subclasses, and its nested classes. If you wish to register a listener globally, you
should register it via the automatic discovery mechanism described in
TestExecutionListener
Configuration.
以下示例展示了如何注册两个 TestExecutionListener
实现:
The following example shows how to register two TestExecutionListener
implementations:
- Java
-
@ContextConfiguration @TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class}) (1) class CustomTestExecutionListenerTests { // class body... }
1 | Register two TestExecutionListener implementations.
|
2 | Register two TestExecutionListener implementations. |
默认情况下,@TestExecutionListeners
提供从超类或封闭类继承侦听器的支持。有关示例和进一步的详细信息,请参见 @Nested
test class configuration 和https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/TestExecutionListeners.html[@TestExecutionListeners
] javadoc。如果您发现您需要切换回使用默认 TestExecutionListener
实现,请参见 Registering TestExecutionListener
Implementations 中的注释。
By default, @TestExecutionListeners
provides support for inheriting listeners from
superclasses or enclosing classes. See
@Nested
test class configuration and the
@TestExecutionListeners
javadoc for an example and further details. If you discover that you need to switch
back to using the default TestExecutionListener
implementations, see the note
in Registering TestExecutionListener
Implementations.