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:
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:
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?
to increase your code coverage, the suggestion is to write tests. It can be unit tests (easiest way) or other tests (Integration test, System tests) which may contribute to coverage when a tool can report coverage for these.
SonarQube is a tool which aims to improve the quality of your code using static analysis techniques to report: code coverage.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With