-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Closed
Copy link
Labels
Milestone
Description
Sam Brannen opened SPR-13180 and commented
Status Quo
#17035 introduced BEFORE_METHOD, BEFORE_EACH_TEST_METHOD, and BEFORE_CLASS modes in @DirtiesContext. In Spring Framework 4.2 RC1, the DirtiesContextTestExecutionListener was updated to support these new BEFORE_\* modes in addition to the existing AFTER_\* modes.
However, there is a problem with having DirtiesContextTestExecutionListener support BEFORE_\* modes since it is configured (by default) to execute after the DependencyInjectionTestExecutionListener. This leads to several undesired side effects:
- The test's
ApplicationContextis closed by theDirtiesContextTestExecutionListenerafter dependencies have been injected into the test instance. - Injected dependencies may therefore attempt to interact with an
ApplicationContextthat is no longer active. - If a test has its
ApplicationContextinjected as a dependency, interaction with the context will likely fail since the context has been closed. - Furthermore, any
TestExecutionListenersregistered after theDirtiesContextTestExecutionListenerwill get a newApplicationContextif they invokeTestContext.getApplicationContext().
Deliverables
- Introduce a new
TestExecutionListenerdedicated to handlingBEFORE_\*modes in@DirtiesContext. - Remove the support for
BEFORE_\*modes fromDirtiesContextTestExecutionListener. - Update all supporting code to ensure that the new
TestExecutionListeneris registered before theDependencyInjectionTestExecutionListener(by default).
Affects: 4.2 RC1
Issue Links:
- Introduce BEFORE_METHOD and BEFORE_CLASS modes for @DirtiesContext [SPR-12429] #17035 Introduce BEFORE_METHOD and BEFORE_CLASS modes for
@DirtiesContext
Referenced from: commits 0aac02d