Annotation Interface TestExecutionListeners
TestExecutionListeners defines class-level metadata for configuring
which TestExecutionListeners should be
registered with a TestContextManager.
@TestExecutionListeners is used to register listeners for a
particular 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.
This annotation may be used as a meta-annotation to create custom
composed annotations. this annotation will
be inherited from an enclosing test class by default. See
@NestedTestConfiguration for details.
Switching to default TestExecutionListener implementations
If you extend a class that is annotated with @TestExecutionListeners
and you need to switch to using the default set of listeners, you
can annotate your class with the following.
// Switch to default listeners
@TestExecutionListeners(listeners = {}, inheritListeners = false, mergeMode = MERGE_WITH_DEFAULTS)
class MyTests extends BaseTests {
// ...
}
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static enumEnumeration of modes that dictate whether or not explicitly declared listeners are merged with the default listeners when@TestExecutionListenersis declared on a class that does not inherit listeners from a superclass. -
可选元素概要
可选元素修饰符和类型可选元素说明booleanWhether or notTestExecutionListenersfrom superclasses should be inherited.Class<? extends TestExecutionListener>[]TheTestExecutionListenersto register with theTestContextManager.The merge mode to use when@TestExecutionListenersis declared on a class that does not inherit listeners from a superclass.Class<? extends TestExecutionListener>[]Alias forlisteners().
-
元素详细资料
-
value
Alias forlisteners().This attribute may not be used in conjunction with
listeners(), but it may be used instead oflisteners().- 默认值:
- {}
-
listeners
TheTestExecutionListenersto register with theTestContextManager.This attribute may not be used in conjunction with
value(), but it may be used instead ofvalue().- 另请参阅:
- 默认值:
- {}
-
inheritListeners
boolean inheritListenersWhether or notTestExecutionListenersfrom superclasses should be inherited.The default value is
true, which means that an annotated class will inherit the listeners defined by an annotated superclass. Specifically, the listeners for an annotated class will be appended to the list of listeners defined by an annotated superclass. Thus, subclasses have the option of extending the list of listeners. In the following example,AbstractBaseTestwill be configured withDependencyInjectionTestExecutionListenerandDirtiesContextTestExecutionListener; whereas,TransactionalTestwill be configured withDependencyInjectionTestExecutionListener,DirtiesContextTestExecutionListener, andTransactionalTestExecutionListener, in that order.@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class }) public abstract class AbstractBaseTest { // ... } @TestExecutionListeners(TransactionalTestExecutionListener.class) public class TransactionalTest extends AbstractBaseTest { // ... }If
inheritListenersis set tofalse, the listeners for the annotated class will shadow and effectively replace any listeners defined by a superclass.- 默认值:
- true
-
mergeMode
TestExecutionListeners.MergeMode mergeModeThe merge mode to use when@TestExecutionListenersis declared on a class that does not inherit listeners from a superclass.Can be set to
MERGE_WITH_DEFAULTSto have locally declared listeners merged with the default listeners.The mode is ignored if listeners are inherited from a superclass.
Defaults to
REPLACE_DEFAULTSfor backwards compatibility.- 默认值:
- REPLACE_DEFAULTS
-