Class DependencyInjectionTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.support.DependencyInjectionTestExecutionListener
- All Implemented Interfaces:
Ordered
,TestExecutionListener
TestExecutionListener
which provides support for dependency
injection and initialization of test instances.- Since:
- 2.5
- Author:
- Sam Brannen, Juergen Hoeller
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Attribute name for aTestContext
attribute which indicates whether the dependencies of a test instance should be reinjected inbeforeTestMethod()
.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeTestMethod
(TestContext testContext) If theREINJECT_DEPENDENCIES_ATTRIBUTE
in the suppliedtest context
has a value ofBoolean.TRUE
, this method will have the same effect asprepareTestInstance()
; otherwise, this method will have no effect.final int
getOrder()
Returns2000
.protected void
injectDependencies
(TestContext testContext) Performs dependency injection and bean initialization for the suppliedTestContext
as described inprepareTestInstance()
.void
prepareTestInstance
(TestContext testContext) Performs dependency injection on thetest instance
of the suppliedtest context
byautowiring
andinitializing
the test instance via its ownapplication context
(without checking dependencies).Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution
-
Field Details
-
REINJECT_DEPENDENCIES_ATTRIBUTE
Attribute name for aTestContext
attribute which indicates whether the dependencies of a test instance should be reinjected inbeforeTestMethod()
. Note that dependencies will be injected inprepareTestInstance()
in any case.Clients of a
TestContext
(e.g., otherTestExecutionListeners
) may therefore choose to set this attribute to signal that dependencies should be reinjected between execution of individual test methods.Permissible values include
Boolean.TRUE
andBoolean.FALSE
.
-
-
Constructor Details
-
DependencyInjectionTestExecutionListener
public DependencyInjectionTestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns2000
.- Specified by:
getOrder
in interfaceOrdered
- Overrides:
getOrder
in classAbstractTestExecutionListener
- Returns:
- the order value
- See Also:
-
prepareTestInstance
Performs dependency injection on thetest instance
of the suppliedtest context
byautowiring
andinitializing
the test instance via its ownapplication context
(without checking dependencies).The
REINJECT_DEPENDENCIES_ATTRIBUTE
will be subsequently removed from the test context, regardless of its value.- Specified by:
prepareTestInstance
in interfaceTestExecutionListener
- Overrides:
prepareTestInstance
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context for the test; nevernull
- Throws:
Exception
- allows any exception to propagate
-
beforeTestMethod
If theREINJECT_DEPENDENCIES_ATTRIBUTE
in the suppliedtest context
has a value ofBoolean.TRUE
, this method will have the same effect asprepareTestInstance()
; otherwise, this method will have no effect.- Specified by:
beforeTestMethod
in interfaceTestExecutionListener
- Overrides:
beforeTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method will be executed; nevernull
- Throws:
Exception
- allows any exception to propagate- See Also:
-
injectDependencies
Performs dependency injection and bean initialization for the suppliedTestContext
as described inprepareTestInstance()
.The
REINJECT_DEPENDENCIES_ATTRIBUTE
will be subsequently removed from the test context, regardless of its value.- Parameters:
testContext
- the test context for which dependency injection should be performed (nevernull
)- Throws:
Exception
- allows any exception to propagate- See Also:
-