Using JUnit Categories with Maven Failsafe plugin

prasopes picture prasopes · Jul 18, 2012 · Viewed 7k times · Source

I'm using JUnit Categories to separate integration tests from unit tests. The Surefire plugin configuration works - it skips the tests annotated with my marker interface IntegrationTest.

However, the Failsafe plugin doesn't pick the integration tests. I've even tried to specify the junit47 provider, but zero tests are run in the integration-test phase.

Here is the pom.xml fragment:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <groups>com.mycompany.test.IntegrationTest</groups>
                <excludedGroups>com.mycompany.test.UnitTest</excludedGroups>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.12</version>
                </dependency>
            </dependencies>
        </plugin>

Here is the Failsafe part of the log:

[INFO] --- maven-failsafe-plugin:2.12:integration-test (default) @ MyProject.war ---
[INFO] Failsafe report directory: /home/stoupa/MyProject/war/target/failsafe-reports
[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Concurrency config is parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Is the provider org.apache.maven.surefire.junitcore.JUnitCoreProvider that can be seen in the log output the right one?

Answer

tunesmith picture tunesmith · Aug 22, 2013

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>