0
votes

I'm trying to get code coverage in a Sonar build using MS Build SonarQube Runner v1.0.1. I wrote a script copied verbatim from the documentation for generating code coverage results from VSTest and I run it as a Post-Build script, passing in test DLLs as arguments, and adding the necessary property key (/d:sonar.cs.vscoveragexml.reportsPaths="%CD%\VisualStudio.coveragexml") to the beginning script arguments.

The script runs, the coverage binary and coverage XML are generated (with valid data in the XML), MS Build SonarQube Runner runs, and stats are uploaded to Sonar - except for the code coverage results. I see it works when I set a static location, e.g. C:\tmp\VisualStudio.coveragexml, but this isn't a good approach when trying to set up many Sonar builds.

Here's a screenshot of the TFS Build Definition: enter image description here

Here's CodeCoverage.bat (copied from the documentation as stated)

"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:"%CD%\VisualStudio.coverage" "%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" %*

"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"%CD%\VisualStudio.coveragexml" "%CD%\VisualStudio.coverage"
1

1 Answers

1
votes

%CD% is a batch variable, and I am not sure it will get correctly expanded from within TFS 2013. Check if TFS 2013 doesn't provide an environment variable that you can use to compute the absolute path to the code coverage report: https://msdn.microsoft.com/en-us/library/hh850448.aspx#env_vars

Moreover, you actually don't need to manually set sonar.cs.vscoveragexml.reportsPaths (or to manually convert the binary coverage report into XML) when you're analyzing your project with TFS 2013 - See https://github.com/SonarSource/sonar-.net-documentation/blob/master/doc/analyze-from-tfs.md ("OPTIONAL - Configure code coverage")