Annotation Interface TestExecutionListeners
TestExecutionListeners
defines class-level metadata for configuring
which TestExecutionListeners
should be
registered with a TestContextManager
.
Typically, @TestExecutionListeners
will be used in conjunction
with @ContextConfiguration
.
This annotation may be used as a meta-annotation to create custom composed annotations.
As of Spring Framework 5.3, this annotation will be inherited from an
enclosing test class by default. See
@NestedTestConfiguration
for details.
- Since:
- 2.5
- Author:
- Sam Brannen
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration of modes that dictate whether or not explicitly declared listeners are merged with the default listeners when@TestExecutionListeners
is declared on a class that does not inherit listeners from a superclass. -
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Whether or notTestExecutionListeners
from superclasses should be inherited.Class<? extends TestExecutionListener>[]
TheTestExecutionListeners
to register with theTestContextManager
.The merge mode to use when@TestExecutionListeners
is declared on a class that does not inherit listeners from a superclass.Class<? extends TestExecutionListener>[]
Alias forlisteners()
.
-
Element Details
-
value
Alias forlisteners()
.This attribute may not be used in conjunction with
listeners()
, but it may be used instead oflisteners()
.- Default:
- {}
-
listeners
TheTestExecutionListeners
to register with theTestContextManager
.This attribute may not be used in conjunction with
value()
, but it may be used instead ofvalue()
.- See Also:
- Default:
- {}
-
inheritListeners
boolean inheritListenersWhether or notTestExecutionListeners
from 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,AbstractBaseTest
will be configured withDependencyInjectionTestExecutionListener
andDirtiesContextTestExecutionListener
; whereas,TransactionalTest
will 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
inheritListeners
is set tofalse
, the listeners for the annotated class will shadow and effectively replace any listeners defined by a superclass.- Default:
- true
-
mergeMode
TestExecutionListeners.MergeMode mergeModeThe merge mode to use when@TestExecutionListeners
is declared on a class that does not inherit listeners from a superclass.Can be set to
MERGE_WITH_DEFAULTS
to have locally declared listeners merged with the default listeners.The mode is ignored if listeners are inherited from a superclass.
Defaults to
REPLACE_DEFAULTS
for backwards compatibility.- Since:
- 4.1
- See Also:
- Default:
- REPLACE_DEFAULTS
-