Tech and Media Labs
This site uses cookies to improve the user experience.




Maven Unit Test Report

Jakob Jenkov
Last update: 2015-05-24

Maven can generate unit test reports in HTML. Maven does so by running the unit tests and recording the results of the unit tests. Maven then generates an HTML report from the unit test results.

Using Maven to generate unit test reports can be useful to see what unit tests fails during the build. Especially if the build is big and takes a long time, because then you might not run all the unit tests from inside your IDE during development. You might only run the unit tests relevant to the changes you make. Then, to check that everything in the project still works, you can tell Maven to run the unit tests and generate a unit test report. You can then read the report to see if any of the unit test have failed during the build.

The Maven unit test report is an HTML file. That means that it can be copied to a server if you need to share it with other developers.

The Maven Surefire Plugin

The Maven unit test reports are generated by the Maven Surefire plugin. Therefore a unit test report is also some times referred to as surefire report.

Generating a Unit Test Report

You generate a Maven unit test report (Surefire unit test report) using the following Maven command:

mvn surefire-report:report

For more information about how the Maven command structure looks, see my Maven commands tutorial.

The generated unit test report can be found in the target/site directory. The unit test report is named surefire-report.html. The path to the unit test report is thus:

your-project/target/site/surefire-report.html

Skipping the Tests

Sometimes you might want Maven to generate a unit test report without running all the unit tests again. You might just want to use the results from the last run. You can get Maven to just generate the unit test report without rerunning the unit tests using this command:

mvn surefire-report:report-only

This command will only generate the unit test report.

Jakob Jenkov




Copyright  Jenkov Aps
Close TOC