Using JUnit Categories with Maven Failsafe plugin

情到浓时终转凉″ 提交于 2019-12-03 11:44:07

By default, the failsafe plugin excludes various files. You have to override that. So change your configuration section to the following:

<configuration>
    <includes>
        <include>**/*.java</include>
    </includes>
    <groups>com.mycompany.test.IntegrationTest</groups>
    <excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
</configuration>
raksja

WORKAROUND

@Categories will give pain as you have to mark each of your integration tests.

Try creating a inttests profile as mentioned below and skip the surefire execution.

 <profile>
        <id>inttests</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <!-- skip the unit tests -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/IT*.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

Prefix or suffix the Integration tests with some string and give that in the includes. By default failsafe picks up all the tests prefixed by IT as the integration tests. Ref: Failsafe Inclusions & Exclusions

Run it using the maven profile command

mvn verify -P inttests

Note: In the above mentioned approach, we need to run the unit tests during build and then inttests separately.

Updates: On JUnit4 Categories With Failsafe Plugin

  • 2.12 - The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? https://issues.apache.org/jira/browse/SUREFIRE-827
  • 2.12.1 - Unable to locate surefire-booter in the list of plugin artifacts https://issues.apache.org/jira/browse/SUREFIRE-896
  • 2.12.2 - has a bug when no tests are there in a module it will look for failsafe-summary.xml and fail https://issues.apache.org/jira/browse/SUREFIRE-901
  • 易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!