Repository navigation
Wrong naming with Junit Jupiter Parallel Execution and nested tests #125
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
Activity
fredrikkarlsson-pervanovo commented
on Dec 1, 2022 AuthorMore actionsMinimal 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.snapResulting snapshot content:
se.pervanovo.bjelin.bjelinservice.servicefactory.ConcurrentTests$NestedTests.one=[ "one" ] se.pervanovo.bjelin.bjelinservice.servicefactory.ConcurrentTests$NestedTests.two=[ "two" ]Reacted by Jack Matthews, Christian Hövelmeyer and Benedek Fauszt- addedenhancementNew feature or requestNew feature or requestbugSomething isn't workingSomething isn't workingand removedenhancementNew feature or requestNew feature or request
on Dec 3, 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 callingcontext.getTestClass(). When I run all the tests in a class, the junit5 hooks are returning the Nested Class instead for some reason.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.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
When running with
@Execution(ExecutionMode.CONCURRENT)on class level and@Nestedtest 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.