类 DependencyInjectionTestExecutionListener
- java.lang.Object
- org.springframework.test.context.support.AbstractTestExecutionListener
- org.springframework.test.context.support.DependencyInjectionTestExecutionListener
- 所有已实现的接口:
Ordered
,TestExecutionListener
public class DependencyInjectionTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener
which provides support for dependency injection and initialization of test instances.- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen, Juergen Hoeller
字段概要
字段 修饰符和类型 字段 说明 static String
REINJECT_DEPENDENCIES_ATTRIBUTE
Attribute name for aTestContext
attribute which indicates whether or not the dependencies of a test instance should be reinjected inbeforeTestMethod()
.从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 DependencyInjectionTestExecutionListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
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.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).从类继承的方法 org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestMethod, beforeTestClass
字段详细资料
REINJECT_DEPENDENCIES_ATTRIBUTE
public static final String REINJECT_DEPENDENCIES_ATTRIBUTE
Attribute name for aTestContext
attribute which indicates whether or not 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
.
构造器详细资料
DependencyInjectionTestExecutionListener
public DependencyInjectionTestExecutionListener()
方法详细资料
getOrder
public final int getOrder()
Returns2000
.- 指定者:
getOrder
在接口中Ordered
- 覆盖:
getOrder
在类中AbstractTestExecutionListener
- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
prepareTestInstance
public void prepareTestInstance(TestContext testContext) throws Exception
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.- 指定者:
prepareTestInstance
在接口中TestExecutionListener
- 覆盖:
prepareTestInstance
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context for the test; nevernull
- 抛出:
Exception
- allows any exception to propagate
beforeTestMethod
public void beforeTestMethod(TestContext testContext) throws Exception
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.- 指定者:
beforeTestMethod
在接口中TestExecutionListener
- 覆盖:
beforeTestMethod
在类中AbstractTestExecutionListener
- 参数:
testContext
- the test context in which the test method will be executed; nevernull
- 抛出:
Exception
- allows any exception to propagate
injectDependencies
protected void injectDependencies(TestContext testContext) throws Exception
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.- 参数:
testContext
- the test context for which dependency injection should be performed (nevernull
)- 抛出:
Exception
- allows any exception to propagate- 另请参阅:
prepareTestInstance(TestContext)
,beforeTestMethod(TestContext)