How to run two maven surefire plugins with different configurations?
Asked Answered
C

2

6

I have 2 test suites. One can be run in parallel and the other must be run sequentially. See definition below.

What I see is that only the second one runs.

I tried to define 2 plugins. Didn't work.

I tried to give them differen execution ID. Didn't work.

I tried to put the configuration under the execution, but got an error that the elements under the configuration aren't allowed, like failIfNoSpecifiedTests.

Any idea how I can run the suites with different configurations - one in parallel and the other sequentially?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <executions>
        <execution>
            <id>SequentialTests</id>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>**/SequentialTests.java</include>
        </includes>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <executions>
        <execution>
            <id>ParallelTests</id>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>**/ParallelTests.java</include>
        </includes>
        <threadCount>10</threadCount>
        <parallel>classes</parallel>
    </configuration>
</plugin>
Centering answered 16/9, 2015 at 10:4 Comment(3)
Sequential sounds like integration tests where as ParallelTests sounds like unit tests?Ole
Both are unit tests. The ones that aren't designed to run in parallel must be run sequentially.Centering
Sorry if they can't run in parallel then they are no unit tests...Ole
R
1

You need to configure a single surefire plugin with multiple executions in the plugin management section of your build. So something like the following:

   <build>
     <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <! any common config-->
          </configuration>
          <!-- multiple executions-->
          <executions>
            <execution>
              <id>default-test</id>
              <configuration>
                <!-- skip default execution since we want to run tests in separate groups, remove this execution if not required for you -->
                <skip>true</skip>
              </configuration>
            </execution>
            <execution>
              <id>firstTestGroup</id>
              <configuration>
                <includes>
                  <include>**/*BlahTest</include>
                </includes>
              </configuration>
              <goals>
                <goal>test</goal>
              </goals>
            </execution>
            <execution>
              <id>secondTestGroup</id>
              <configuration>
                <excludes>
                  <exclude>**/*BlahTest</exclude>
                </excludes>
              </configuration>
              <goals>
                <goal>test</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
Richierichlad answered 25/3, 2022 at 11:24 Comment(2)
How is this solution different than @roiros' suggestion?Centering
It is more explicit and specifies where to put it - plugin management section - with a concrete working example that shows the default execution that needs to be skipped (or overridden if you want) etc.. this worked for me with failsafe-plugin (which extends surefire) as well as other plugins.. you have put in a comment mentioning that it is not working for the previous solution by @roiros, thought this might help.. is it still not working?Richierichlad
B
0

Please put the different configurations under the 2 separate execution nodes - instead as a top level element, as a top level element they are overloading each other while under separate execution nodes they can live 'side by side' e.g:

<execution> 
  <id>SequentialTests</id>
  <configuration>...<configuration>
</execution>

<execution>
  <id>ParallelTests</id>
  <configuration>...<configuration>
</execution>
Brachiopod answered 21/9, 2015 at 8:57 Comment(1)
Not working, All configuration sub-tags are being ignored, like <includes>, <failIfNoSpecifiedTests>, etc. Even IDEA highlights configuration sub-elements in red, to indicate they aren't accepted.Centering

© 2022 - 2024 — McMap. All rights reserved.