Maven Surefire Plugin
https://maven.apache.org/surefire/maven-surefire-plugin/
Requirements: Maven 2.2.1 or 3.x, and JDK 1.6 or higher. Due to wrong formatting of console text messages in Maven Version prior to 3.1.0 it is highly recommended to use Maven 3.1.0 or higher.
The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats:
- Plain text files (*.txt)
- XML files (*.xml)
By default, these files are generated in ${basedir}/target/surefire-reports/TEST-*.xml.
The schema for the Surefire XML reports is available at Surefire XML Report Schema.
For an HTML format of the report, please see the Maven Surefire Report Plugin.
Goals Overview
The Surefire Plugin has only one goal:
- surefire:test runs the unit tests of an application.
Usage
General instructions on how to use the Surefire Plugin can be found on the usage page. Some more specific use cases are described in the examples listed below. Last but not least, users occasionally contribute additional examples, tips or errata to the plugin's wiki page. In case you still have questions regarding the plugin's usage, please have a look at the FAQ and feel free to contact the user mailing list. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the mail archive.
If you feel like the plugin is missing a feature or has a defect, you can file a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our source repository and will find supplementary information in the guide to helping with Maven.
Examples
The following examples show how to use the Surefire Plugin in more advanced use cases:
- Using TestNG
- Using JUnit
- Using POJO Tests
- Skipping Tests
- Skip After Failure
- Inclusions and Exclusions of Tests
- Running a Single Test
- Re-run Failing Tests
- Class Loading and Forking
- Debugging Tests
- Using System Properties
- Configuring the Classpath
- Selecting Providers
- Fork Options and Parallel Test Execution
- Using Console Logs
- Shutdown of Forked JVM
Usage
https://maven.apache.org/surefire/maven-surefire-plugin/usage.html
Best practice is to define the version of the Surefire Plugin that you want to use in either your pom.xml or a parent pom.xml:
<project>
[...]
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>
The Surefire Plugin can be invoked by calling the test phase of the build lifecycle.
mvn test
Using Different Testing Providers
Tests in your test source directory can be any combination of the following:
- TestNG
- JUnit (3.8 or 4.x)
- POJO
Which providers are available is controlled simply by the inclusion of the appropriate dependencies (i.e., junit:junit or junit:junit-dep for JUnit and org.testng:testng 4.7+ for TestNG). Since this is required to compile the test classes anyway, no additional configuration is required.
Note that any normal Surefire integration works identically no matter which providers are in use - so you can still produce a Cobertura report and a Surefire results report on your project web site for your TestNG tests, for example.
The POJO provider above allows you to write tests that do not depend on either of JUnit and TestNG. It behaves in the same way, running all test* methods that are public in the class, but the API dependency is not required. To perform assertions, the JDK 1.4 assert keyword can be used. See Using POJO Tests for more information.
All of the providers support the Surefire Plugin parameter configurations. However, there are additional options available if you are running TestNG tests (including if you are using TestNG to execute your JUnit tests, which occurs by default if both are present in Surefire).
See Using TestNG for more information.
Maven Surefire Report Plugin
http://maven.apache.org/surefire/maven-surefire-report-plugin/
The Surefire Report Plugin parses the generated TEST-*.xml files under ${basedir}/target/surefire-reports and renders them using DOXIA, which creates the web interface version of the test results.
Goals Overview
The Surefire Report Plugin only has one goal (the other is a workaround):
- surefire-report:failsafe-report-only This goal does not run the tests, it only builds the IT reports. See SUREFIRE-257
- surefire-report:report Generates the test results report into HTML format.
- surefire-report:report-only This goal does not run the tests, it only builds the reports. It is provided as a work around for SUREFIRE-257
Note: As of version 2.8 this plugin requires Maven Site Plugin 2.1 or newer to work properly. Version 2.7.2 and older are still compatible with newer Surefire versions, so mixing is possible.
Usage
General instructions on how to use the Surefire Report Plugin can be found on the usage page. Some more specific use cases are described in the examples listed below. Last but not least, users occasionally contribute additional examples, tips or errata to the plugin's wiki page.
In case you still have questions regarding the plugin's usage, please have a look at the FAQ and feel free to contact the user mailing list. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the mail archive.
If you feel like the plugin is missing a feature or has a defect, you can file a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our source repository and will find supplementary information in the guide to helping with Maven.
Dependency Information
http://maven.apache.org/surefire/maven-surefire-report-plugin/dependency-info.html
Apache Maven
<dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.21.0</version> <type>maven-plugin</type> </dependency>
Apache Ivy
<dependency org="org.apache.maven.plugins" name="maven-surefire-report-plugin" rev="2.21.0"> <artifact name="maven-surefire-report-plugin" type="maven-plugin" /> </dependency>
Groovy Grape
@Grapes( @Grab(group='org.apache.maven.plugins', module='maven-surefire-report-plugin', version='2.21.0') )
Scala SBT
libraryDependencies += "org.apache.maven.plugins" % "maven-surefire-report-plugin" % "2.21.0"
Leiningen
[org.apache.maven.plugins/maven-surefire-report-plugin "2.21.0"]
Project Dependency Management
http://maven.apache.org/surefire/maven-surefire-report-plugin/dependency-management.html
compile
The following is a list of compile dependencies in the DependencyManagement of this project. These dependencies can be included in the submodules to compile and run the submodule:
test
The following is a list of test dependencies in the DependencyManagement of this project. These dependencies can be included in the submodules to compile and run unit tests for the submodule:
| GroupId | ArtifactId | Version | Type | License |
|---|---|---|---|---|
| org.powermock | powermock-api-mockito2 | 2.0.0-beta.5 | jar | The Apache Software License, Version 2.0 |
| org.powermock | powermock-core | 2.0.0-beta.5 | jar | The Apache Software License, Version 2.0 |
| org.powermock | powermock-module-junit4 | 2.0.0-beta.5 | jar | The Apache Software License, Version 2.0 |
- Log in to post comments
