How do I get my Maven Integration tests to run How do I get my Maven Integration tests to run java java

How do I get my Maven Integration tests to run


The Maven build lifecycle now includes the "integration-test" phase for running integration tests, which are run separately from the unit tests run during the "test" phase. It runs after "package", so if you run "mvn verify", "mvn install", or "mvn deploy", integration tests will be run along the way.

By default, integration-test runs test classes named **/IT*.java, **/*IT.java, and **/*ITCase.java, but this can be configured.

For details on how to wire this all up, see the Failsafe plugin, the Failsafe usage page (not correctly linked from the previous page as I write this), and also check out this Sonatype blog post.


You can set up Maven's Surefire to run unit tests and integration tests separately. In the standard unit test phase you run everything that does not pattern match an integration test. You then create a second test phase that runs just the integration tests.

Here is an example:

    <plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-surefire-plugin</artifactId>      <configuration>        <excludes>          <exclude>**/*IntegrationTest.java</exclude>        </excludes>      </configuration>      <executions>        <execution>          <id>integration-test</id>          <goals>            <goal>test</goal>          </goals>          <phase>integration-test</phase>          <configuration>            <excludes>              <exclude>none</exclude>            </excludes>            <includes>              <include>**/*IntegrationTest.java</include>            </includes>          </configuration>        </execution>      </executions>    </plugin>


I have done EXACTLY what you want to do and it works great. Unit tests "*Tests" always run, and "*IntegrationTests" only run when you do a mvn verify or mvn install. Here it the snippet from my POM. serg10 almost had it right....but not quite.

  <plugin>    <!-- Separates the unit tests from the integration tests. -->    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-surefire-plugin</artifactId>    <configuration>       <!-- Skip the default running of this plug-in (or everything is run twice...see below) -->       <skip>true</skip>       <!-- Show 100% of the lines from the stack trace (doesn't work) -->       <trimStackTrace>false</trimStackTrace>    </configuration>    <executions>       <execution>          <id>unit-tests</id>          <phase>test</phase>          <goals>             <goal>test</goal>          </goals>          <configuration>                <!-- Never skip running the tests when the test phase is invoked -->                <skip>false</skip>             <includes>                   <!-- Include unit tests within integration-test phase. -->                <include>**/*Tests.java</include>             </includes>             <excludes>               <!-- Exclude integration tests within (unit) test phase. -->                <exclude>**/*IntegrationTests.java</exclude>            </excludes>          </configuration>       </execution>       <execution>          <id>integration-tests</id>          <phase>integration-test</phase>          <goals>             <goal>test</goal>          </goals>          <configuration>            <!-- Never skip running the tests when the integration-test phase is invoked -->             <skip>false</skip>             <includes>               <!-- Include integration tests within integration-test phase. -->               <include>**/*IntegrationTests.java</include>             </includes>          </configuration>       </execution>    </executions>  </plugin>

Good luck!