13

I have a multi-module project and I have failsafe defined in the root pom like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <includes>
            <include>**/*IntegrationTest.java</include>
            <include>**/*JourneyTest.java</include>
            <include>**/*CucumberFeatureTest.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <excludes>
            <exclude>**/*IntegrationTest.java</exclude>
            <exclude>**/*JourneyTest.java</exclude>
            <exclude>**/*CucumberFeatureTest.java</exclude>
        </excludes>
    </configuration>
</plugin>

Failsafe is not defined anywhere else in my other poms. If I run mvn verify, it skips integration tests (it runs unit tests). But if I run mvn test-compile failsafe:integration-test, it runs integration tests.

I'm under the assumption that failsafe is supposed to run in both of these situations. So why doesn't it run when I type mvn verify?

UPDATE: Just noticed that this was wrapped around these tags:

<build>
    <pluginManagement> <!-- oops -->
        <plugins>
            <plugin>

I feel like this explains the cause, but I'm not sure why unit tests still run like you'd expect with mvn verify and mvn test. Why does surefire work differently from failsafe in this respect?

kryger
  • 12,906
  • 8
  • 44
  • 65
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356

2 Answers2

11

You need to bind failsafe's integration test goal to maven's integration-test and verify phases. By default the failsafe-plugin isn't included in a vanilla maven project. You need to add it. So even though there is an integration-test lifecycle, by default it is not included (well, at least doesn't run the maven-failsafe-plugin). You add it to the integration-test and verify phases (it needs both, it will fail the build at the verify phase only [if the preceding integration-tests failed], so that the post-integration lifecycle phase still has a chance to run and cleanup resources, hence the name "fail safe").

   <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-failsafe-plugin</artifactId>
       <version>2.19</version>
       <configuration>
           <includes>
               <include>**/*IntegrationTest.java</include>
               <include>**/*JourneyTest.java</include>
               <include>**/*CucumberFeatureTest.java</include>
           </includes>
       </configuration>
       <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
   </plugin>
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
JJF
  • 2,681
  • 2
  • 18
  • 31
  • That change had no affect on the outcome. I'll update the original question to include this – Daniel Kaplan Nov 25 '15 at 20:23
  • 1
    Yes, binding the failsafe plugin to the execution is the correct solution. Unfortunately, as with a lot of Maven documentation, it's not pointed out well enough. This setup is documented in the [failsafe plugin's official docs](https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html). – rdguam Apr 16 '16 at 01:32
  • For followers, see Daniel Kaplan's "update" to the question for why it didn't affect his outcome (but is the right answer nonetheless). – rogerdpack May 15 '18 at 20:47
0

I encountered a similar issue when running mvn verify as the integration tests were not executed, but only the unit tests. It worked after marking skipTests to false:

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <skipTests>false</skipTests>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>           
</plugin>
Cristi B.
  • 651
  • 7
  • 17