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 —
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 —
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‘.
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 –
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.
Once I made this change and triggered another TFS Build, I was able to see the Code Coverage details in the SonarQube site.