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
Showing
想要评论请 注册 或 登录