SonarQube does not show the Code Coverage but shows the number of unit tests


(Felipe Oriani) #1

Hey guys.

It is my first time with SonarQube and it show me great results and there is something wrong that I don’t know how to fix it.

We have some Unit Tests using the MSTest Framework and using the AzureDevOps with a CI environment we run all the unit tests when a build pipeline starts. It works fine and I have done it when I built the SonarQube build pipeline on the VSTS. following the documentation.

It works and I have added the argument on the Prepare Analysis on SonarQube on the VSTS to indicate how to find the coverage file:


(I am not sure if this sintax is correct here ot find the trx file)

In the Visual Studio Test build step I checked the option Code Coverage Enabled and when I run this build process (unit tests runs fine) I checked on the generated folders by the VSTSAgent (on our build machine) that the .trx file was generated inside a TestResults folder. When the analysis finishes on SonarQube, I can see the number of the unit tests but there is code coverage available and it shows me 0%. In the Run Code Analysis log I can see it was performed by this:

2019-01-23T13:31:01.1264760Z 11:31:01.112 INFO: Sensor C# [csharp] (done) | time=21407ms
2019-01-23T13:31:01.1265441Z 11:31:01.112 INFO: Sensor C# Unit Test Results Import [csharp]
2019-01-23T13:31:01.7602567Z 11:31:01.752 INFO: Parsing the Visual Studio Test Results file E:\Agent02\_work\165\.\s\TestResults\SRV-01$_SRV-01_2019-01-23_11_27_22.trx
2019-01-23T13:31:01.8458444Z 11:31:01.830 INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=718ms
2019-01-23T13:31:01.8460380Z 11:31:01.830 INFO: Sensor Zero Coverage Sensor
2019-01-23T13:31:02.4975307Z 11:31:02.268 INFO: Sensor Zero Coverage Sensor (done) | time=438ms

and in the SonarQube:


I would like to know how can I fix it? Am I missing any extra configuration? Should I install a new build step (or extra installation on the VSTS extensions)?

Thank you.

  • SonarQube 7.5 Community Edition
  • SonarC# Plugin
  • Scanner for MSBuild

(Sven Myrin) #2

You get this working?

I don’t use the enable code coverage checkbox. Instead I specify a runsettings file with the relevant code coverage settings. Your build should generate a .coverage file with the coverage data. I believe that is how SQ gets its data.

(Felipe Oriani) #3

No, I am using the Visual Studio Community on my build server and I think that’s the reason why I can’t get the test covarage on the sonarQube.

(Sven Myrin) #4

Are you using vNext builds with the SonarQube custom tasks from marketplace?


(Felipe Oriani) #5

Yes, I am using the same buildsteps on Azure Devops but no code covarage results are available on sonarQube. Any ideia or solution for VS Community?

(Sven Myrin) #6

After the test run completes, does the build agent have a testresults folder containing the .trx, .coverage, and .coveragexml files?