Skip to content

@DirtiesContext not applied when class-level @EnabledIf evaluates to false #26694

@igorakkerman

Description

@igorakkerman

When a JUnit 5 test class is annotated with @EnabledIf and @DirtiesContext with @EnabledIf's property loadContext set to true, if its expression evaluates to false, the context loaded through the annotation is not cleaned up afterwards.

If the expression evaluates to true and the tests are actually run, the context is cleaned up correctly.

A workaround is to put @EnabledIf on each test method, instead of the class.

I ran into this issue running Kafka container tests conditionally, when Kafka consumers were created through @EnableAutoConfiguration and were left over after the test was skipped. They were consuming messages of other tests that would run afterwards, breaking those tests.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions