Honor class-level @DirtiesContext if test class is disabled via SpEL
Prior to this commit, if a test class annotated with @DirtiesContext and @EnabledIf/@DisabledIf with `loadContext = true` was disabled due to the evaluated SpEL expression, the ApplicationContext would not be marked as dirty and closed. The reason is that @EnabledIf/@DisabledIf are implemented via JUnit Jupiter's ExecutionCondition extension API which results in the entire test class (as well as any associated extension callbacks) being skipped if the condition evaluates to `disabled`. This effectively prevents any of Spring's TestExecutionListener APIs from being invoked. Consequently, the DirtiesContextTestExecutionListener does not get a chance to honor the class-level @DirtiesContext declaration. This commit fixes this by implementing part of the logic of DirtiesContextTestExecutionListener in AbstractExpressionEvaluatingCondition (i.e., the base class for @EnabledIf/@DisabledIf support). Specifically, if the test class for an eagerly loaded ApplicationContext is disabled, AbstractExpressionEvaluatingCondition will now mark the test ApplicationContext as dirty if the test class is annotated with @DirtiesContext. Closes gh-26694
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<Logger name="org.springframework.test.context.support.DelegatingSmartContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.AbstractGenericContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.AnnotationConfigContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener" level="warn" />
|
||||
<Logger name="org.springframework.test.context.support.TestPropertySourceUtils" level="trace" />
|
||||
<Logger name="org.springframework.beans" level="warn" />
|
||||
<Logger name="org.springframework.test.web.servlet.result" level="debug" />
|
||||
|
||||
Reference in New Issue
Block a user