Teten Nugraha



Generate Codecoverage Report with Jacoco and Sonarqube

Generate Codecoverage Report with Jacoco and Sonarqube

Teten Nugraha's photo
Teten Nugraha
ยทFeb 6, 2020ยท

3 min read

Photo by William Iven on Unsplash

Based on my previous article we talked about JUnit on Service Layer and JUnit on Controller Layer. And now, we will talk about how to generate Codecoverate Report using Jacoco plugin and Sonarqube.

As you already know, Sonarqube is for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on 20+ programming languages.

JaCoCo is a free code coverage library for Java, which has been created by the EclEmma team based on the lessons learned from using and integration existing libraries for many years.


  • You have downloaded source code on this link.

  • You have download and setting Sonarqube and you can use community edition for this one.

Check Before ..

Lets check again Unit Test that we have writed. Check on UserServiceTest and do Unit Test check.

and then, we check again UserControllerTest.

Okay, looks fine.

Start Sonarqube Server

Open your sonarqube directory and click StartSonar.batch (is depend on your operating system on your laptop)

wait for a moment until sonar server is running.

Generate Code Coverage Using Jacoco

  • Add below Jacoco configuration on pom.xml properties section
  • and add also Jacoco plugin still on pom.xml under <plugin> section
  • after that, open terminal or command prompt and direct to root directory of project. Execute this maven command to build project.

mvn clean install

wait until build process has finished like this.

Look, on coverage report under target folder there is file called jacoco-unit.exec. That file who used by Sonarqube to generate and display report about codecoverage, code quality , etc.

keep your terminal on root folder of project. and then execute this maven command to connect with Sonarqube.

mvn sonar:sonar

wait until build process has finished.

after finished, There are two link for you to open sonarqube on browser. click that link and automatically open your browser.

this page is about report from out project. Seen that Coverage around 91.5%. Unit Test 16. and if you wanto to know detail of codecoverage from whole your code, click code tab.

from that data, we can improve our code to be better again.


Jacoco and Sonarqube is important for many programmer. With both, we can improve quality of code little by little.

If it was interesting or helpful to you, please do press the ๐Ÿ‘ clap button and help others find this story too or if you wanna talk internally with me , reach me in [linktr.ee/teten_nugraha](https://linktr.ee/...

Did you know you could give up to 50 claps?

Did you find this article valuable?

Support Teten Nugraha by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
Share this