Annotation Type TestExecutionListeners
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface TestExecutionListeners
TestExecutionListeners
defines class-level metadata for configuring whichTestExecutionListeners
should be registered with aTestContextManager
.Typically,
@TestExecutionListeners
will be used in conjunction with@ContextConfiguration
.This annotation may be used as a meta-annotation to create custom composed annotations.
- Since:
- 2.5
- Author:
- Sam Brannen
- See Also:
TestExecutionListener
,TestContextManager
,ContextConfiguration
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
inheritListeners
Whether or notTestExecutionListeners
from superclasses should be inherited.Class<? extends TestExecutionListener>[]
listeners
TheTestExecutionListeners
to register with theTestContextManager
.TestExecutionListeners.MergeMode
mergeMode
The merge mode to use when@TestExecutionListeners
is declared on a class that does not inherit listeners from a superclass.Class<? extends TestExecutionListener>[]
value
Alias forlisteners()
.
Element Detail
value
@AliasFor("listeners") Class<? extends TestExecutionListener>[] value
Alias forlisteners()
.This attribute may not be used in conjunction with
listeners()
, but it may be used instead oflisteners()
.- Default:
- {}
listeners
@AliasFor("value") Class<? extends TestExecutionListener>[] 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:
ServletTestExecutionListener
,DirtiesContextBeforeModesTestExecutionListener
,DependencyInjectionTestExecutionListener
,DirtiesContextTestExecutionListener
,TransactionalTestExecutionListener
,SqlScriptsTestExecutionListener
,EventPublishingTestExecutionListener
- Default:
- {}
inheritListeners
boolean inheritListeners
Whether 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 mergeMode
The 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:
TestExecutionListeners.MergeMode
- Default:
- org.springframework.test.context.TestExecutionListeners.MergeMode.REPLACE_DEFAULTS