Class AbstractJUnit4SpringContextTests
- java.lang.Object
- org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
- All Implemented Interfaces:
Aware
,ApplicationContextAware
- Direct Known Subclasses:
AbstractTransactionalJUnit4SpringContextTests
@TestExecutionListeners({ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.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 environment.Concrete subclasses should typically declare a class-level
@ContextConfiguration
annotation to configure the application contextresource locations
orannotated 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
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
, as of Spring Framework 4.2 you can useSpringClassRule
andSpringMethodRule
and specify your runner of choice via@RunWith(...)
.
NOTE: As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
- Since:
- 2.5
- Author:
- Sam Brannen
- See Also:
ContextConfiguration
,TestContext
,TestContextManager
,TestExecutionListeners
,ServletTestExecutionListener
,DirtiesContextBeforeModesTestExecutionListener
,DependencyInjectionTestExecutionListener
,DirtiesContextTestExecutionListener
,AbstractTransactionalJUnit4SpringContextTests
,AbstractTestNGSpringContextTests
Field Summary
Fields Modifier and Type Field Description protected ApplicationContext
applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.protected Log
logger
Logger available to subclasses.
Constructor Summary
Constructors Constructor Description AbstractJUnit4SpringContextTests()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.
Field Detail
applicationContext
protected ApplicationContext applicationContext
TheApplicationContext
that was injected into this test instance viasetApplicationContext(ApplicationContext)
.
Constructor Detail
AbstractJUnit4SpringContextTests
public AbstractJUnit4SpringContextTests()
Method Detail
setApplicationContext
public final void setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContext
to be used by this test instance, provided viaApplicationContextAware
semantics.- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Parameters:
applicationContext
- the ApplicationContext that this test runs in- See Also:
BeanInitializationException