Setting up properly SonarQube’s for Code Coverage

Tags: , , , ,



I’m using JUnit5 on a SpringBoot backend application server using Maven. Here is the sonar-project.properties file that is at the root of the project:

sonar.host.url=https://sonarcloud.io
sonar.login=xxx
sonar.organization=xxx
sonar.projectKey=xxx

sonar.sourceEncoding=UTF-8
sonar.language=java
sonar.java.source=12

sonar.sources=src/main/java
sonar.test=src/test
sonar.java.binaries=target/classes
sonar.junit.reportPaths=target/test-results/TEST-**.xml

I use the sonar-scanner command line to run update the project after a build/test.

The Overview board on sonar-cloud looks like this:

overview

I at least got the unit tests to be recognized, but somehow I’m still at 0% in terms of code coverage. Furthermore, here is the Measures board:

measures

Apparently, my tests do not cover any lines whatsoever. Now, I’m aware that this means that I most probably didn’t hook up the test-results properly, but I’m not sure how to do that.

What puzzles me, too, is that despite SonarQube recognizing my tests, it actually says that the lines-of-code of the tests themselves aren’t tested. What is this supposed to mean?

Testing tests?

Answer

From SonarQube’s documentation:

SonarSource analyzers do not run your tests or generate reports. They only import pre-generated reports.

A popular library for generating code coverage for Java is Jacoco.

SonarQube provides this guide to create and import Jacoco’s reports.



Source: stackoverflow