This to-the-point tutorial describes the failsafe plugin, one of the core plugins of the Maven build tool.
For an overview of the other core plugins, refer to this article.
2. Plugin Goals
The failsafe plugin is used for integration tests of a project. It has two goals:
- integration-test – run integration tests; this goal is bound to the integration-test phase by default
- verify – verify that the integration tests passed; this goal is bound to the verify phase by default
3. Goal Execution
This plugin runs methods in test classes just like the surefire plugin. We can configure both plugins in similar ways. However, there’re some crucial differences between them.
First, unlike surefire (see this article) which is included in the super pom.xml, the failsafe plugin with its goals must be explicitly specified in the pom.xml to be part of a build lifecycle:
<plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.21.0</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> ... </configuration> </execution> </executions> </plugin>
The newest version of this plugin is here.
Second, the failsafe plugin runs and verifies tests using different goals. A test failure in the integration-test phase doesn’t fail the build straight away, allowing the phase post-integration-test to execute, where clean-up operations are performed.
Failed tests, if any, are only reported during the verify phase, after the integration test environment has been torn down properly.
In this article, we introduced the failsafe plugin, comparing it with the surefire plugin, another popular plugin used for testing.
The complete source code for this tutorial can be found over on GitHub.