Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't "mvn verify" run my integration tests?

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?

like image 953
Daniel Kaplan Avatar asked Nov 25 '15 18:11

Daniel Kaplan


1 Answers

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>
like image 71
JJF Avatar answered Oct 27 '22 19:10

JJF