Search code examples
maventestngmaven-surefire-plugin

Maven Surefire only "default-test" run custom executions ignored


I am using maven 3.5.4, maven-surefire-plugin 2.19 (I tried maven-surefire-plugin 2.22 also - same result). Here's the build section of my POM:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>20</threadCount>
            </configuration>
            <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <excludedGroups>switch-enabled</excludedGroups>
                    </configuration>
                </execution>
                <execution>
                    <id>other-tests</id>
                    <configuration>
                        <groups>switch-enabled</groups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I have two sets of unit tests that need to run separately (due to a static boolean variable, thus I set up a TestNG group and have all the tests that need the switch to be on in that group).

Surefire only runs the "default-test" execution and ignore the other execution. I tried the following as well but it also didn't work - no tests were run instead:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>20</threadCount>
            </configuration>
            <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
                <execution>
                    <id>true-tests</id>
                    <configuration>
                        <groups>switch-enabled</groups>
                    </configuration>
                </execution>
                <execution>
                    <id>false-tests</id>
                    <configuration>
                        <excludedGroups>switch-enabled</excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

What have I done wrong?


Solution

  • I had the same issue with surefire plugin. I would suggest you to move your tests run configuration to the testng .xml file, that would run each set separately and would also let you config parallel run for each:

        <suite name="Test-Suite">
        <test name="Test first set" parallel="20" preserve-order="true">
            <classes>
                <class name="domain.tests.com.TestA"/>
                <class name="domain.tests.com.TestB"/>
       // Classes of first set here..
            </classes>
        </test>
        <test name="Test second set" parallel="20" preserve-order="true">
            <classes>
                <class name="domain.tests.com.TestC"/>
                <class name="domain.tests.com.TestD"/>
       // Classes of second set here..
            </classes>
        </test>
        </suite>