Maven Failsafe Plugin:
- The Failsafe Plugin is designed to run integration tests and as the name implies, when it fails, it does so in a safe way.
- The Failsafe Plugin has only two goals:
- failsafe:integration-test runs the integration tests of an application.
- failsafe:verify verifies that the integration tests of an application passed.
- The Maven lifecycle has four phases for running integration tests:
- pre-integration-test for setting up the integration test environment.
- integration-test for running the integration tests.
- post-integration-test for tearing down the integration test environment.
- verify for checking the results of the integration tests.
- Command : mvn test or mvn clean test
- The Failsafe Plugin generates reports in two different file formats:
- Plain text files (*.txt)
- XML files (*.xml)
- By default, these files are generated in ${basedir}/target/failsafe-reports/TEST-*.xml.
Pom.xml
<dependencies> <!– Test framework which will be used by Failsafe plugin. Version number is mandatory –> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <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> <configuration> <!– Disable unit tests –> <skip>true</skip> </configuration> </plugin> </plugins> </build> |
Command | Information | |
1 | mvn test | run tests(unit and integration tests) using a suitable unit testing framework These tests should not require the code be packaged or deployed |
2 | mvn -Dtest=TestCircle test | Running a Single a class |
3 | mvn -Dtest=TestCircle#mytest test | Running a specific method in a class |
4 | mvn install -DskipTests or mvn install -Dmaven.test.skip=true | Directly running install command(install the package in local repository) |
Comparison Maven surefire and failsafe plugins :
maven-surefire-plugin | maven-failsafe-plugin | |
Main purpose | unit tests | integration tests |
Bound to build phase | test | pre-integration-testintegration-testpost-integration-testverify |
Build fails in phase | test | verify |
Default wildcard pattern | **/Test*.java**/*Test.java**/*TestCase.java | **/IT*.java**/*IT.java**/*ITCase.java |
Default output directory | ${basedir}/target/surefire-reports | ${basedir}/target/failsafe-reports |