@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Inherited public @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.
TestExecutionListener
,
TestContextManager
,
ContextConfiguration
Modifier and Type | Optional Element and Description |
---|---|
boolean |
inheritListeners
Whether
TestExecutionListeners from superclasses
and enclosing classes should be inherited. |
Class<? extends TestExecutionListener>[] |
listeners
The
TestExecutionListeners to register with
the TestContextManager . |
TestExecutionListeners.MergeMode |
mergeMode
The merge mode to use when
@TestExecutionListeners is
declared on a class that does not inherit listeners from
a superclass or enclosing class. |
Class<? extends TestExecutionListener>[] |
value
Alias for
listeners() . |
@AliasFor(value="listeners") public abstract Class<? extends TestExecutionListener>[] value
listeners()
.
This attribute may not be used in conjunction with
listeners()
, but it may be used instead of listeners()
.
@AliasFor(value="value") public abstract Class<? extends TestExecutionListener>[] listeners
TestExecutionListeners
to register with
the TestContextManager
.
This attribute may not be used in conjunction with
value()
, but it may be used instead of value()
.
ServletTestExecutionListener
,
DirtiesContextBeforeModesTestExecutionListener
,
ApplicationEventsTestExecutionListener
,
DependencyInjectionTestExecutionListener
,
DirtiesContextTestExecutionListener
,
TransactionalTestExecutionListener
,
SqlScriptsTestExecutionListener
,
EventPublishingTestExecutionListener
public abstract boolean inheritListeners
TestExecutionListeners
from superclasses
and enclosing classes should be inherited.
The default value is true
, which means that an annotated class
will inherit the listeners defined by an annotated superclass or
enclosing class. Specifically, the listeners for an annotated class will be
appended to the list of listeners defined by an annotated superclass or
enclosing class. Thus, subclasses and nested classes have the option of
extending the list of listeners. In the following example,
AbstractBaseTest
will be configured with
DependencyInjectionTestExecutionListener
and
DirtiesContextTestExecutionListener
; whereas,
TransactionalTest
will be configured with
DependencyInjectionTestExecutionListener
,
DirtiesContextTestExecutionListener
, and
TransactionalTestExecutionListener
, in that order.
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class }) public abstract class AbstractBaseTest { // ... } @TestExecutionListeners(TransactionalTestExecutionListener.class) public class TransactionalTest extends AbstractBaseTest { // ... }
If inheritListeners
is set to false
, the listeners for
the annotated class will shadow and effectively replace any
listeners defined by a superclass or enclosing class.
public abstract TestExecutionListeners.MergeMode mergeMode
@TestExecutionListeners
is
declared on a class that does not inherit listeners from
a superclass or enclosing class.
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 or enclosing class.
Defaults to REPLACE_DEFAULTS
for backwards compatibility.
TestExecutionListeners.MergeMode