Cobertura is a free Java code coverage tool – calculates the percentage of code accessed by unit tests. In this tutorial, we will show you how to use Maven to generate the Cobertura code coverage report for your project.

1. Cobertura Code Coverage Report

Do nothing, just type the following Maven command to download and run the maven-cobertura-plugin automatically.

c:\project> mvn cobertura:cobertura

Results :

Tests run: 16, Failures: 0, Errors: 0, Skipped: 0

[INFO] <<< cobertura-maven-plugin:2.6:cobertura (default-cli) @ TestNG <<<
[INFO] --- cobertura-maven-plugin:2.6:cobertura (default-cli) @ TestNG ---
[INFO] Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Report time: 82ms

//Mkyong : Not sure what caused this error, but Cobertura still works well.
[ERROR] net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler 

INFO: Cobertura: Loaded information on 5 classes.

[INFO] Cobertura Report generation was successful.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.309s
[INFO] Finished at: Mon Jan 13 21:45:56 SGT 2014
[INFO] Final Memory: 25M/307M
[INFO] ------------------------------------------------------------------------

Maven will generate the Cobertura code coverage report at ${project}/target/site/cobertura/index.html.

More Examples
Please refer to this Cobertura Maven Plugin for more examples.

Figure : Sample of Cobertura code coverage report, index page, look like a JavaDoc.


Figure : Detail page.


2. Maven Site + Cobertura Report

To integrate Cobertura report into the Maven site, add the following to the reporting section.


	<!-- Normally, we take off the dependency report, saves time. -->

	// integrate maven-cobertura-plugin to project site 


Creating Maven project site

mvn site

Output - ${project}/site/index.html



  1. Cobertura code coverage tool
  2. Cobertura Maven Plugin
  3. Maven - Creating a site
  4. Java Code Coverage Tools
  5. Stackoverflow : What is the proper way to use Cobertura with Maven
  6. Maven + Emma code coverage Example