Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fredrikkarlsson-pervanovo opened this issue Dec 1, 2022 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@fredrikkarlsson-pervanovo

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.

@fredrikkarlsson-pervanovo
Copy link
Author

fredrikkarlsson-pervanovo commented Dec 1, 2022

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"
]

@jackmatt2 jackmatt2 added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Dec 3, 2022
@jackmatt2
Copy link
Member

jackmatt2 commented Dec 4, 2022

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.

this.snapshotVerifier = new SnapshotVerifier(getSnapshotConfig(), testClass, failOnOrphans);

@jackmatt2 jackmatt2 added the help wanted Extra attention is needed label Jan 24, 2023
@Christian-Hovelmeyer
Copy link

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
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants