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

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 )

Google+ photo

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

Connecting to %s