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:
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"