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

msbuild
tests
vsts
sonarqube

(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:

sonar.cs.vstest.reportsPaths="**\TestResults\*.trx"

(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:

code-coverage-zero

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 7.10.0.7896
  • Scanner for MSBuild 4.5.0.1761-net46