SonarQube 6.5 – Code Coverage Result is not displayed


I have installed SonarQube 6.5 and have the server up and running. I have completed the integration with our TFS CI/CD Build. Everything works great end to end – with the only exception of Code Coverage. So now the question is how do I get Code Coverage to work?

I have been actively blogging about the issues I have been facing while setting up SonarQube in my project and also posting the resolutions. If you are on the same journey and start seeing errors, make sure to check out my last few blog posts on SonarQube —

SonarQube 6.5 – Issues while configuring SQL Server Database

SonarQube Error – End of Central Directory record could not be found

SonarQube SQL Error – String or binary data would be truncated

Moving on to the issue of Code Coverage not being displayed in SonarQube, looking at the TFS Build logs, I get the below error message —

2017-10-25T13:18:25.9706006Z 08:18:23.97 Fetching code coverage report information from TFS…
2017-10-25T13:18:25.9706006Z 08:18:23.986 Attempting to locate a test results (.trx) file…
2017-10-25T13:18:25.9706006Z 08:18:24.204 Looking for TRX files in: C:\Program Files\TFS2015Agent\_work\20\TestResults
2017-10-25T13:18:25.9706006Z 08:18:24.204 Located a test results file: C:\Program Files\TFS2015Agent\_work\20\TestResults\EISTFSSVC_EISHQAPTA01T 2017-10-25 08_18_02.trx
2017-10-25T13:18:25.9706006Z WARNING: File is not under the project directory and cannot currently be analysed by SonarQube.

I referred the SonarQube TFS Integration documentation link —
https://docs.sonarqube.org/display/SCAN/From+Team+Foundation+Server+2015+or+Visual+Studio+Team+Services

Visual Studio Test Task

It states that to import code coverage into SonarQube, add the Visual Studio Test build task after the build one and tick ‘Code Coverage Enabled‘.

Code Coverage Enabled

In the Visual Studio Test build task, I have the Code Coverage Enabled checkbox checked , but I still do not get the code coverage details in SonarQube. The Code Coverage does display in the TFS Build side though.

This seem to be a bug with SonarQube latest scanner, since I had it working with the earlier versions. Only after upgrading to SonarQube 6.5 and using the latest scanners, I started seeing these errors.

I raised this issue in the SonarQube Google Group in an anticipation of getting response from someone who has faced this issue –
https://groups.google.com/forum/#!topic/sonarqube/gUwX7RawOEs

However after doing some more googling I figured that it is a legit issue & SonarSource Team is already aware of and has an open ticket for fixing it —
Scanner for MSBuild through VSTS extension no longer import coveragexml

Hopefully this will be fixed in future releases. But for now there is a workaround of simply adding —  /d:sonar.cs.vscoveragexml.reportsPaths=”**\*.coveragexml” into the Additional Settings of the SonarQube Scanner for MSBuild – Begin Analysis (new) task. This will ensure that SonarQube explicitly picks up the VisualStudio.coveragexml file.

Additional Settings

Once I made this change and triggered another TFS Build, I was able to see the Code Coverage details in the SonarQube site.

Code Coverage Up



Categories: C#, SonarQube, Visual Studio

5 replies

  1. The problem seems to be fixed with SonarQube VSTS/TFS Marketplace Extension version 4.3.1 (maybe it was even fixed in version 4.1, but it certainly works with 4.3.1).

    Liked by 1 person

  2. The problem seems to be fixed with SonarQube VSTS/TFS Marketplace Extension version 4.3.1 (maybe it was even fixed in version 4.1, but it certainly works with 4.3.1).

    Liked by 1 person

    • As it turned out not all build agent versions are able to cope correctly with the SonarQube extension version 4.3.1. Build agent version 2.112.0 was not able to pick-up build jobs with SonarQube tasks of version 4.*.
      I got a message that read “waiting for an enabled agent. all possible agents are disabled.” when queuing a build even though all capabilities seemed to be satisfied on the build agents.
      After updating my build agents to version 2.122.1 the build jobs were executed successfully and the code coverage was correctly reported.

      Liked by 1 person

  3. In case the code-coverage is not yet supported by SonarCloud, you maybe need to convert the “.coverage” files to “.coveragexml”. See this project for more info: https://github.com/StefH/CoverageConverter

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: