Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running tests in parallel with maven surefire plugin

Recently got a new job, I'm working on a Maven and Micronaut project - I'm new to Micronaut, and if you're not familiar, its an alternative to Spring.

Using this as a guide: https://www.baeldung.com/maven-junit-parallel-tests

I'm trying to get our integration tests to run in parallel, in an attempt to speed up our tests. I have added the required configuration to the pom.xml file. I have tweaked this lots, with different combinations of settings (including ones I found on other SO posts).

But when I run the tests, with and without this added config, the time it takes to run them is exactly the same - 1 minute and 38 seconds. So I don't think its working. Although don't know what my expected output on the console should look like if it is working?

In the tests, none of them are using @RunWith, its using the default, which should be okay.

This is the pom. Can anyone advise please? Thanks.

<profiles>
    <profile>
      <id>integration</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, performance</excludedGroups>
              <parallel>classes</parallel>
              <threadCount>10</threadCount>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>performance</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, integration</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>all</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>none</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
<build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
          <excludedGroups>integration, performance</excludedGroups>
          <parallel>classes</parallel>
          <threadCount>10</threadCount>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
like image 976
Chris Avatar asked Feb 12 '21 10:02

Chris


1 Answers

I had the same problem and tried every combination of:

  1. maven-surefire-plugin (version 2.22.0)

  2. maven-failsafe-plugin (version 2.22.0)

    • This is another plugin that is basically the same but designed for running integration tests, in that it doesn't stop after the first failed test.
  3. The parallel/threadCount configuration you mention.

  4. These different plugin configurations specified at https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-config-params and https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution. As in this:

       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>2.22.0</version>
         <configuration>
           <properties>
             <configurationParameters>
               junit.jupiter.execution.parallel.enabled=true
               junit.jupiter.execution.parallel.mode.default=same_thread
               junit.jupiter.execution.parallel.mode.classes.default=concurrent
             </configurationParameters>
           </properties>
         </configuration>
      </plugin>
    

The only combination that worked was 2 (maven-failsafe-plugin) and 4 (configurationParameters).

like image 162
alwaysLearningABC Avatar answered Oct 19 '22 10:10

alwaysLearningABC