I’m trying to get junit5 tests to run in parallel using the maven surefire plugin, as described on https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html. Despite configuration that looks correct, I can’t get them to run in parallel. I’ll paste my configuration and what I’ve tried and experienced so far. Any help is greatly appreciated!
My surefire plugin configuration looks like this: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.21.0</version> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.2.0</version> </dependency> </dependencies> </plugin> And I have a maven profile setup with additional configuration for our integration tests, which includes the parallel configuration. The commented out configurations indicate all the things I’ve tried. <profile> <id>integration-tests-local</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire.version}</version> <configuration> <parallel>classes</parallel> <threadCount>4</threadCount> <useUnlimitedThreads>true</useUnlimitedThreads> <!-- <useUnlimitedThreads>true</useUnlimitedThreads>--> <!-- <threadCountClasses>4</threadCountClasses>--> <!-- <threadCountMethods>4</threadCountMethods>--> <!-- <threadCountSuites>4</threadCountSuites>--> <!-- <threadCount>4</threadCount>--> <parallelOptimized>false</parallelOptimized> <!-- <parallelMavenExecution>true</parallelMavenExecution>--> <perCoreThreadCount>false</perCoreThreadCount> <excludes> <exclude>none</exclude> </excludes> <includes> <include>**/*IntegrationTests*.java</include> </includes> </configuration> </plugin> </plugins> </build> The project is structured with a parent pom.xml and several sub-projects. The tests are in the “integration-tests” module, which pulls in the surefire plugin with no additional configuration: <plugin> <artifactId>maven-surefire-plugin</artifactId> </plugin> I mention the sub-project because it means that the maven command I’m running looks like this (I’ve tried with/without the “-T”): mvn -T 4 test -e -pl integration-tests -am -Pintegration-tests-local For the purposes of debugging, I’ve created 10 .java files named TestIntegrationTests1.java through TestIntegrationTests10.java, each of which has 10 unit tests all of which look like this: package com.axon.scorpius.integration_tests; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; /** * Tests. */ public class TestIntegrationTests1 { @Test void test1() { try { Thread.sleep(1000); } catch (InterruptedException ex) { System.out.println("Interrupted exception: " + ex); } assertTrue(true); } … 9 identical tests My hope is that when I run “mvn test” (I’m running locally in iTerm on a Macbook), these 10 test classes will run in parallel (at least partially), but they run serially, as seen here: INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests4 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.057 s - in com.axon.scorpius.integration_tests.TestIntegrationTests4 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests6 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.029 s - in com.axon.scorpius.integration_tests.TestIntegrationTests6 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests10 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.025 s - in com.axon.scorpius.integration_tests.TestIntegrationTests10 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests2 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.027 s - in com.axon.scorpius.integration_tests.TestIntegrationTests2 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests7 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.032 s - in com.axon.scorpius.integration_tests.TestIntegrationTests7 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests5 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.027 s - in com.axon.scorpius.integration_tests.TestIntegrationTests5 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests1 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.032 s - in com.axon.scorpius.integration_tests.TestIntegrationTests1 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests3 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.036 s - in com.axon.scorpius.integration_tests.TestIntegrationTests3 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests9 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.013 s - in com.axon.scorpius.integration_tests.TestIntegrationTests9 [INFO] Running com.axon.scorpius.integration_tests.TestIntegrationTests8 [INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 11.026 s - in com.axon.scorpius.integration_tests.TestIntegrationTests8 [INFO] [INFO] Results: [INFO] [WARNING] Tests run: 113, Failures: 0, Errors: 0, Skipped: 2