This tutorial demonstrates the surefire 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 Goal
We can run the tests of a project using the surefire plugin. By default, this plugin generates XML reports in the directory target/surefire-reports.
This plugin has only one goal, test. This goal is bound to the test phase of the default build lifecycle, and the command mvn test will execute it.
The surefire plugin can work with the test frameworks JUnit and TestNG. No matter which framework we use, the behavior of surefire is the same.
By default, surefire automatically includes all test classes whose name starts with Test, or ends with Test, Tests or TestCase.
We can change this configuration using the excludes and includes parameters, however:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.21.0</version> <configuration> <excludes> <exclude>DataTest.java</exclude> </excludes> <includes> <include>DataCheck.java</include> </includes> </configuration> </plugin>
With this configuration, test cases in the DataCheck class are executed while the ones in DataTest aren't.
We can find the latest version of the plugin here.
In this quick article, we went through the surefire plugin, describing its only goal as well as how to configure it.
As always, the complete source code for this tutorial can be found over on GitHub.