@TestExecutionListeners(value={ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,ApplicationEventsTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,EventPublishingTestExecutionListener.class}) public abstract class AbstractJUnit4SpringContextTests extends Object implements ApplicationContextAware
ApplicationContext testing support
in a JUnit 4 environment.
Concrete subclasses should typically declare a class-level
@ContextConfiguration annotation to
configure the application context resource 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 appropriate TestExecutionListeners manually.
This class explicitly registers the following TestExecutionListener
implementations. If you want to switch to using the default set of
listeners, see the class-level Javadoc for
@TestExecutionListeners for details.
ServletTestExecutionListener
DirtiesContextBeforeModesTestExecutionListener
ApplicationEventsTestExecutionListener
DependencyInjectionTestExecutionListener
DirtiesContextTestExecutionListener
EventPublishingTestExecutionListener
This class serves only as a convenience for extension.
SpringRunner, @ContextConfiguration,
@TestExecutionListeners, etc.SpringRunner, you can use
SpringClassRule and
SpringMethodRule
and specify your runner of choice via @RunWith(...).NOTE: This class requires JUnit 4.12 or higher.
ContextConfiguration,
TestContext,
TestContextManager,
TestExecutionListeners,
ServletTestExecutionListener,
DirtiesContextBeforeModesTestExecutionListener,
ApplicationEventsTestExecutionListener,
DependencyInjectionTestExecutionListener,
DirtiesContextTestExecutionListener,
EventPublishingTestExecutionListener,
AbstractTransactionalJUnit4SpringContextTests,
AbstractTestNGSpringContextTests| Modifier and Type | Field and Description |
|---|---|
protected ApplicationContext |
applicationContext
The
ApplicationContext that was injected into this test instance
via setApplicationContext(ApplicationContext). |
protected Log |
logger
Logger available to subclasses.
|
| Constructor and Description |
|---|
AbstractJUnit4SpringContextTests() |
| Modifier and Type | Method and Description |
|---|---|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the
ApplicationContext to be used by this test instance,
provided via ApplicationContextAware semantics. |
protected final Log logger
@Nullable protected ApplicationContext applicationContext
ApplicationContext that was injected into this test instance
via setApplicationContext(ApplicationContext).public final void setApplicationContext(ApplicationContext applicationContext)
ApplicationContext to be used by this test instance,
provided via ApplicationContextAware semantics.setApplicationContext in interface ApplicationContextAwareapplicationContext - the ApplicationContext that this test runs inBeanInitializationException