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

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
1 Like

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.

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.

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

Capture0

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?

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

How this issue is resolved?
Really appreciate help on it I am also facing similar issue

Hi Team

I am running sonar analysis on my code but it doesn’t show code coverage. Also, unit tests are not showing in the report too. WHat am I doing wrong here ?

Please help asap

2 posts were split to a new topic: Code coverage import problem

This topic has a mix of problems for C#, Java and this doesn’t help us help you.

Please open 1 topic per problem, clearly defining what your problems are.

Also some docs you can refer to:

You can take a look at the discussion on Code Coverage is not shown in the SonarCloud.io to make sure you run the commands from the same folder and you can check the paths inside the reports are correct.

Also, read these troubleshooting steps..

I am closing this topic due to inactivity, as the initial question opener didn’t follow up.

If you have a similar question, please open a new topic, in which you should clearly state:

  • the SonarQube version you are using
  • the language you are analyzing
  • the steps you are doing, with logs for each step
  • the error you are getting

Thanks,
Andrei