Skip to content

Wrong naming with Junit Jupiter Parallel Execution and nested tests #125

Description

When running with @Execution(ExecutionMode.CONCURRENT) on class level and @Nested test classes, it seems that all tests are named after the first nested test class that is run and then all tests are added to that snapshot file.

Expected behaviour is of course that the names are the same with and without parallel execution of junit 5 tests.

Activity

  1. fredrikkarlsson-pervanovo commented on Dec 1, 2022

    @fredrikkarlsson-pervanovo
    Author

    Minimal example:

    package se.pervanovo.bjelin.bjelinservice.servicefactory;
    
    import org.junit.jupiter.api.DisplayName;
    import org.junit.jupiter.api.Nested;
    import org.junit.jupiter.api.Test;
    import org.junit.jupiter.api.extension.ExtendWith;
    import org.junit.jupiter.api.parallel.Execution;
    import org.junit.jupiter.api.parallel.ExecutionMode;
    import org.springframework.boot.test.context.SpringBootTest;
    
    import au.com.origin.snapshots.Expect;
    import au.com.origin.snapshots.junit5.SnapshotExtension;
    
    @SpringBootTest
    @ExtendWith(SnapshotExtension.class)
    @Execution(ExecutionMode.CONCURRENT)
    public class ConcurrentTests {
        @Test
        void one(Expect expect) {
            expect.toMatchSnapshot("one");
        }
    
        @Nested
        @DisplayName("nested")
        public class NestedTests {
            @Test
            void two(Expect expect) {
                expect.toMatchSnapshot("two");
            }
        }
    }
    

    Resulting snapshot name: ConcurrentTests$NestedTests.snap

    Resulting snapshot content:

    se.pervanovo.bjelin.bjelinservice.servicefactory.ConcurrentTests$NestedTests.one=[
      "one"
    ]
    
    
    se.pervanovo.bjelin.bjelinservice.servicefactory.ConcurrentTests$NestedTests.two=[
      "two"
    ]
    
  2. added
    enhancementNew feature or request
    bugSomething isn't working
    and removed
    enhancementNew feature or request
    on Dec 3, 2022
  3. jackmatt2 commented on Dec 4, 2022

    @jackmatt2
    Collaborator

    It seems that this might be a bug in the JUnit Jupiter API BeforeAllCallback. When I run the test by itself, it correctly returns the current class name calling context.getTestClass(). When I run all the tests in a class, the junit5 hooks are returning the Nested Class instead for some reason.

    https://github.com/origin-energy/java-snapshot-testing/blob/cee4af4ba194f8a06b3988332bc12812624ea542/java-snapshot-testing-junit5/src/main/java/au/com/origin/snapshots/junit5/SnapshotExtension.java#L34

  4. Christian-Hovelmeyer commented on Jun 26, 2023

    @Christian-Hovelmeyer

    Furthermore: When you mix test methods in and outside @nested classes, one .snap.debug file will not get deleted after test completion. In the example above, ConcurrentTests.snap.debug will remain inside snapshots.
    When you move @test one(...) into a @nested class, everything gets cleaned up properly.

    It seems book-keeping of files created is buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions