Maven: Plugin: maven-surefire-plugin

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:

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.


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):

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.

Examples

The following examples show how to use the Surefire Report Plugin in more advanced use cases:


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 Buildr

'org.apache.maven.plugins:maven-surefire-report-plugin:maven-plugin:2.21.0'

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')
)

Gradle/Grails

compile 'org.apache.maven.plugins:maven-surefire-report-plugin: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:

GroupId ArtifactId Version Type License
com.google.code.findbugs jsr305 2.0.3 jar The Apache Software License, Version 2.0
commons-io commons-io 2.5 jar Apache License, Version 2.0
junit junit 4.12 jar Eclipse Public License 1.0
org.apache.commons commons-lang3 3.5 jar Apache License, Version 2.0
org.apache.maven maven-artifact 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-core 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-model 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-plugin-api 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-plugin-descriptor 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-project 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-settings 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven maven-toolchain 2.2.1 jar The Apache Software License, Version 2.0
org.apache.maven.plugin-tools maven-plugin-annotations 3.5 jar Apache License, Version 2.0
org.apache.maven.reporting maven-reporting-api 3.0 jar The Apache Software License, Version 2.0
org.apache.maven.shared maven-common-artifact-filters 1.3 jar The Apache Software License, Version 2.0
org.apache.maven.shared maven-shared-utils 0.9 jar Apache License, Version 2.0
org.apache.maven.shared maven-verifier 1.6 jar Apache License, Version 2.0
org.apache.maven.surefire maven-surefire-common 2.21.0 jar Apache License, Version 2.0
org.apache.maven.surefire surefire-api 2.21.0 jar Apache License, Version 2.0
org.apache.maven.surefire surefire-booter 2.21.0 jar Apache License, Version 2.0
org.apache.maven.surefire surefire-grouper 2.21.0 jar Apache License, Version 2.0
org.apache.maven.surefire surefire-logger-api 2.21.0 jar Apache License, Version 2.0
org.codehaus.plexus plexus-component-annotations 1.6 jar The Apache Software License, Version 2.0
org.codehaus.plexus plexus-java 0.9.3 jar Apache License, Version 2.0
org.easytesting fest-assert 1.4 jar LICENSE.txt
org.fusesource.jansi jansi 1.13 jar The Apache Software License, Version 2.0
org.hamcrest hamcrest-library 1.3 jar New BSD License
org.mockito mockito-core 2.13.0 jar The MIT License

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

 

Tags