类 AbstractJUnit4SpringContextTests
- java.lang.Object
- org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
- 所有已实现的接口:
Aware
,ApplicationContextAware
@TestExecutionListeners({ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,EventPublishingTestExecutionListener.class}) public abstract class AbstractJUnit4SpringContextTests extends Object implements ApplicationContextAware
Abstract base test class which integrates the Spring TestContext Framework with explicitApplicationContext
testing support in a JUnit 4 environment.Concrete subclasses should typically declare a class-level
@ContextConfiguration
annotation to configure the application contextresource locations or component classes. If your test does not need to load an application context, you may choose to omit the@ContextConfiguration
declaration and to configure the appropriateTestExecutionListeners
manually.The following
TestExecutionListeners
are configured by default:ServletTestExecutionListener
DirtiesContextBeforeModesTestExecutionListener
DependencyInjectionTestExecutionListener
DirtiesContextTestExecutionListener
EventPublishingTestExecutionListener
This class serves only as a convenience for extension.
- If you do not wish for your test classes to be tied to a Spring-specific class hierarchy, you may configure your own custom test classes by using
SpringRunner
,@ContextConfiguration
,@TestExecutionListeners
, etc. - If you wish to extend this class and use a runner other than the
SpringRunner
, you can useSpringClassRule
andSpringMethodRule
and specify your runner of choice via@RunWith(...)
.
NOTE: This class requires JUnit 4.12 or higher.
- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen
- 另请参阅:
ContextConfiguration
,TestContext
,TestContextManager
,TestExecutionListeners
,ServletTestExecutionListener
,DirtiesContextBeforeModesTestExecutionListener
,DependencyInjectionTestExecutionListener
,DirtiesContextTestExecutionListener
,EventPublishingTestExecutionListener
,AbstractTransactionalJUnit4SpringContextTests
,AbstractTestNGSpringContextTests
字段概要
字段 修饰符和类型 字段 说明 protected ApplicationContext
applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.protected Log
logger
Logger available to subclasses.
构造器概要
构造器 构造器 说明 AbstractJUnit4SpringContextTests()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.
字段详细资料
applicationContext
@Nullable protected ApplicationContext applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.
构造器详细资料
AbstractJUnit4SpringContextTests
public AbstractJUnit4SpringContextTests()
方法详细资料
setApplicationContext
public final void setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.- 指定者:
setApplicationContext
在接口中ApplicationContextAware
- 参数:
applicationContext
- the ApplicationContext that this test runs in- 另请参阅:
BeanInitializationException