devlopp
devlopp

Reputation: 437

How to analyze unit test files in SonarQube 6.7?

I have a modular project created with maven. Here is the tree of my project :

project
-module1
   -src/main/java
   -src/test
-module2
   -src/main/java
   -src/test
-module3
   -src/main/java
   -src/test
-module4
   -src/main/java
   -src/test
-src

On the sonar configuration file I put :

sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/*Test*/**
sonar.exclusions=**/*Test*/**

The unit tests that I have on the project are developed with Junit. With this configuration I still have 0% of test coverage.

enter image description here

Is the configuration correct?

Upvotes: 1

Views: 7141

Answers (1)

Simon Schrottner
Simon Schrottner

Reputation: 4764

Attention do not mistake analyzing unittest-files for running unittests and generating coverage.

Sonarqube will not detect/compute your coverage based on your unittests, which you configured to analyze properly. Sonarqube will only analyse it for sonarqube issues.

For unittest coverage you need to use eg. jacoco during test run, and provide the jacoco reports, and ideally the unittest reports during the sonar analysis like:

sonar.junit.reportPaths=<paths to junit xml - comma separated>
sonar.jacoco.reportPaths=<paths to jacoco reports - comma separated>

This means, to get such kind of data, you should ideally run your tests first, generate those reports, and also provide those properties to your scanner, before running the scan.

For more detailed information on how to achieve this i recommend:

Upvotes: 4

Related Questions