Integration and Functional Testing with Maven 2.0
"The Failsafe Plugin is designed to run integration tests while the Surefire Plugins is designed to run unit tests." - http://maven.apache.org/plugins/maven-failsafe-plugin/
See below for the Failsafe section.
However, some people are using Surefire for integration testing - not least because Failsafe only came along some time after Surefire ...
Put your Integration tests in a separate module
If you use this approach, you keep all your tests for a module in the testSourceDirectory, e.g. src/test/java. By default the Failsafe Maven Plugin looks for integration tests matching the patterns */IT.java, **/IT.java and */*ITCase.java. You will notice that these bindings do not overlap with the default surefire bindings. To use the Maven Failsafe Plugin you need to add the following to your pom.xml file.
<project> [...] <build> <plugins> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project>
You will then have the following lifecycle bindings
Plugin execution goal
The advantage to using the Maven Failsafe Plugin is that it will not stop the build during the integration-test phase if there are test failures. The recommendation is that you do not directly invoke the pre-integration-test, integration-test or post-integration-test phases but that instead you run integration tests by specifying the verify phase, e.g.
This allows you to set-up your integration test environment during the pre-integration-test phase, run your integration tests during the integration-test phase, cleanly tear-down your integration test environment during the post-integration-test phase before finally checking the integration test results and failing the build if necessary. Here is an example using jetty for hosting an integration test environment:
<project> [...] <build> <plugins> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.16</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <stopPort>8005</stopPort> <stopKey>STOP</stopKey> <contextPath>/</contextPath> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Rumor has it that a future version of Maven will support something like src/it/java in the integration-test phase, in addition to src/test/java in the test phase.
- How do I get my Maven Integration tests to run?
- How to use Maven Surefire plug-in with different groups for test and integration-test?
- Integration testing with maven 2.0