VStest code coverage report in jenkins VStest code coverage report in jenkins jenkins jenkins

VStest code coverage report in jenkins


I have struggled this for a long time, finally I found we can use "CodeCoverage.exe" "ReportGenarator.exe" and "Cobertura plugin" to show perfect coverage report.

"ReportGenarator.exe" can be get from https://github.com/danielpalme/ReportGenerator/releases

  • first use "CodeCoverage.exe" translate .coverage file to .xml file
    "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze -output:./TestResults/coverage.xml ./TestResults/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.coverage"
  • second use ReportGenarator.exe translate vstest xml format to Cobertura xml format
    "ReportGenerator_4.4.7\net47\ReportGenerator.exe" -reports:./TestResults/coverage.xml -targetdir:./TestResults -reporttypes:cobertura
  • finally install cobertura plugin use it to collect xml file, here give a pipeline useage example
    post {        always {            cobertura coberturaReportFile: './TestResults/Cobertura.xml'        }    }
  • the result just like thiscobertura.xml report


To display the coverage report you need to convert it in XML format and use MSTest Plugin to publish the report. MSTest Plugin recommends (https://wiki.jenkins-ci.org/display/JENKINS/MSTest+Plugin) to use third party application to convert in XML format and powershell (you will need to install pugin for it) to run it.

However you can convert it with PowerShell only. There is example of script:

$coverageFile = $(get-ChildItem -Path .\TestResults -Recurse -Include *coverage)[0]$xmlCoverageFile = ".\TestResults\vstest.coveragexml"Add-Type -path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Coverage.Analysis.dll"[string[]] $executablePaths = @($coverageFile)[string[]] $symbolPaths = @()$info = [Microsoft.VisualStudio.Coverage.Analysis.CoverageInfo]::CreateFromFile($coverageFile, $executablePaths, $symbolPaths);$data = $info.BuildDataSet()$data.WriteXml($xmlCoverageFile)

You maybe will need to fix the path to Microsoft.VisualStudio.Coverage.Analysis.dll according to your VS version.


Following ghking's answer, cobertura complains that the xml is not found although it's on the disk. I have to remove './' from the path, so that cobertura is able to find the file.

   post {       always {           cobertura coberturaReportFile: 'TestResults/Cobertura.xml'       }   }