JaCoCo Java Code Coverage + Maven example

Jacoco is used to measure the code coverage of application. In this tutorial we will understand how to configure Jacoco in maven and how to use Jacoco to see code coverage report.

Technologies Used:

  • Eclipse Mars
  • Maven 3.3.9
  • Java 8

1. Eclipse Create Maven Java Project

1.1 In Eclipse create a Maven project File->New->Project->Maven Project, Select create a simple project and click on next

1.2 Enter groupId & artifactId as shown in below screen and click on finish.

2. Project Structure

The project has the following components

  • Sample Arithmetic Operations Class
  • Sample Arithmetic Operations JUnit Test Class
  • pom.xml with Junit and Jacoco dependencies

3. pom.xml

Configure Junit and Jacoco as shown in pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" 
	<name>Mathematical Operations</name>


							<!-- Sets the path to the file which contains the execution data. -->

							<!-- Sets the output directory for the code coverage report. -->

4. Sample Arithmetic Operations Class

In this class method ‘add’ is created which accepts two integer parameters and returns sum.


package math.operation;

public class ArithmeticOperations {

	public Integer add(Integer a, Integer b)
		return a+b;


5. Sample Arithmetic Operations Junit Test Class

Testcase is created for ‘add’ method.


package math.operation;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class ArithmeticOperationsTest {

	public void testAdd()
		ArithmeticOperations operations = new ArithmeticOperations();
		Integer actual = operations.add(2, 6);
		Integer expected = 8;
		assertEquals(expected, actual);	


6. Run Application

Right Click Project->Run as ->Maven test. Jacoco output report will be generated in target directory under jacoco-ut folder

7. Output

7.1 To see the output go to target directory and open index.html from jacoco-ut folder in browser. Overall Report for class ArithmeticOperations is shown below

7.2 Clicking on each method in above figure gives detailed report. Here it shows green coloured line indicating which line is covered by unit test.


Download Source Code

Download – jacoco-maven-example.zip (2 KB)


  1. JaCoCo Java Code Coverage Library
  2. Wikipedia – Java Code Coverage Tools
  3. JaCoCo – Maven Plug-in – EclEmma

About the Author

author image
Prakash Nayak
Loves to learn new technologies or programming languages.


Leave a Reply

newest oldest most voted

Thank you for the post . I just imported your project as it is but getting msg as – “Skipping JaCoCo execution due to missing execution data file:” and no jacoco file getting generated . COuld you please help.

Philip Ardley
Philip Ardley

You will need to remove the and tags.
After some modifications this was my result: https://github.com/philard/Syntax-highlighter/blob/master/pom.xml


Hi Yong. Thanks for your post. if possible to please post how to get Integration test coverage report by executing the test manually. For example deploying the war to Tomcat and then how to integrate Jacoco agent + source code to get coverage report. Thanks.

Ganesh Bala
Ganesh Bala

Good tutorial


Maven Artifact Id should be in lowercase, according to official Maven naming conventions.