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 explicitApplicationContexttesting support in a JUnit environment.Concrete subclasses should typically declare a class-level
@ContextConfigurationannotation to configure the application contextresource locationsorannotated classes. If your test does not need to load an application context, you may choose to omit the@ContextConfigurationdeclaration and to configure the appropriateTestExecutionListenersmanually.The following
TestExecutionListenersare configured by default:ServletTestExecutionListenerDirtiesContextBeforeModesTestExecutionListenerDependencyInjectionTestExecutionListenerDirtiesContextTestExecutionListener
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 useSpringClassRuleandSpringMethodRuleand 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 ApplicationContextapplicationContextTheApplicationContextthat was injected into this test instance viasetApplicationContext(ApplicationContext).protected LogloggerLogger available to subclasses.
Constructor Summary
Constructors Constructor Description AbstractJUnit4SpringContextTests()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetApplicationContext(ApplicationContext applicationContext)Set theApplicationContextto be used by this test instance, provided viaApplicationContextAwaresemantics.
Field Detail
applicationContext
protected ApplicationContext applicationContext
TheApplicationContextthat was injected into this test instance viasetApplicationContext(ApplicationContext).
Constructor Detail
AbstractJUnit4SpringContextTests
public AbstractJUnit4SpringContextTests()
Method Detail
setApplicationContext
public final void setApplicationContext(ApplicationContext applicationContext)
Set theApplicationContextto be used by this test instance, provided viaApplicationContextAwaresemantics.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
applicationContext- the ApplicationContext that this test runs in- See Also:
BeanInitializationException