Skip to content

DirtiesContext does not clean up context properly #35318

@maxhov

Description

@maxhov

I am having trouble getting consecutive tests with clean contexts to work and I am not sure what I am doing wrong here. I suspect that the context is not cleaned properly.

When running multiple tests consecutively, the context of the previous test does not seem to be cleaned up properly when using @DirtiesContext(classMode = ClassMode.BEFORE_CLASS). In my particular case, I am running some tests with a @EnableJpaAuditing configured and some without. Running tests individually, they all pass, but running them together in a certain order, they influence eachother. I would expect the context to be clean for the entire test class when using @DirtiesContext(classMode = ClassMode.BEFORE_CLASS).

I created a reproducer here: https://github.com/maxhov/dirties-context/blob/master/src/test/java/com/example/dirtiescontext/DirtiesContextTest.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulestatus: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions