mangusbrother
mangusbrother

Reputation: 4156

Running test categories separately

I need to run groups of my tests in separate stages (first run group A, then run group B as if you had just started running tests)

So i decided to use a combination of maven-failsafe-plugin and junit test categories

I have the following configuration:

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                    <groups>my.categories.IntegrationTest</groups>
                    <excludedGroups>my.categories.ProfiledIntegrationTest, my.categories.MvcTest, my.categories.ExchangeRateTest</excludedGroups>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                    <groups>my.categories.ProfiledIntegrationTest</groups>
                    <excludedGroups>my.categories.IntegrationTest, my.categories.MvcTest, my.categories.ExchangeRateTest</excludedGroups>
                </configuration>
                <executions>
                    <execution>
                        <id>profiled-integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                    <groups>my.categories.MvcTest</groups>
                    <excludedGroups>my.categories.ProfiledIntegrationTest, my.categories.IntegrationTest, my.categories.ExchangeRateTest</excludedGroups>
                </configuration>
                <executions>
                    <execution>
                        <id>mvc-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                    <groups>my.categories.ExchangeRateTest</groups>
                    <excludedGroups>my.categories.MvcTest, my.categories.ProfiledIntegrationTest, my.categories.IntegrationTest</excludedGroups>
                </configuration>
                <executions>
                    <execution>
                        <id>exchange-rate-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
            </plugin>
        </plugins>

However maven runs my unit tests (surefire) and then the last instance of the maven failsafe plugin only (it ignores the previous 3)

How can i make it run them as well please?

Upvotes: 1

Views: 215

Answers (1)

mangusbrother
mangusbrother

Reputation: 4156

The solution was as mentioned by JF Meier

you need to only have one instance of the plugin, and run them as seperate executions

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <groups>my.categories.IntegrationTest</groups>
                            <excludedGroups>my.categories.ProfiledIntegrationTest, my.categories.MvcTest, my.categories.ExchangeRateTest</excludedGroups>
                        </configuration>
                    </execution>
                    <execution>
                        <id>profiled-integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <groups>my.categories.ProfiledIntegrationTest</groups>
                            <excludedGroups>my.categories.IntegrationTest, my.categories.MvcTest, my.categories.ExchangeRateTest</excludedGroups>
                        </configuration>
                    </execution>
                    <execution>
                        <id>mvc-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <groups>my.categories.MvcTest</groups>
                            <excludedGroups>my.categories.ProfiledIntegrationTest, my.categories.IntegrationTest, my.categories.ExchangeRateTest</excludedGroups>
                        </configuration>
                    </execution>
                    <execution>
                        <id>exchange-rate-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <groups>my.categories.ExchangeRateTest</groups>
                            <excludedGroups>my.categories.MvcTest, my.categories.ProfiledIntegrationTest, my.categories.IntegrationTest</excludedGroups>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
            </plugin>
        </plugins>

Upvotes: 2

Related Questions