Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VStest code coverage report in jenkins

I am setting CI for .Net project using Jenkins.

I used MSTest Plugin and VStestrunner plugin to run test. Now I have .trx file and .Coverage file I am facing problem in displaying code coverage report

Please help me is you know any plugin to do this.

like image 207
vishal mane Avatar asked May 13 '15 12:05

vishal mane


People also ask

How do I run MSTest in Jenkins?

To configure a MSTest installation, go to Manage Jenkins -> Configure System (or Manage Jenkins -> Global Tool Configuration in Jenkins 2.8, possibly earlier) and add a MSTest installation. Name is mandatory. If Path to MSTest is left blank, the default is MSTest.exe. MSTestRunner can be used as a build step.

Which of the plugin analyzes the test execution reports files generated by MSTest and Vstest console?

The MSTest plugin analyzes the test execution reports (TRX) files generated by mstest and vstest. console. These files include a test execution summary, and detailed data about what happened during the tests execution.

Which plugin is used for getting code coverage for .NET projects?

JetBrains dotCover is a . NET unit test runner and code coverage tool that integrates with Visual Studio and JetBrains Rider. Make sure you know to what extent your code is covered with unit tests. dotCover calculates and reports statement-level code coverage in applications targeting .


2 Answers

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 this cobertura.xml report
like image 69
ghking Avatar answered Oct 12 '22 03:10

ghking


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.

like image 3
Volodymyr Baydalka Avatar answered Oct 12 '22 04:10

Volodymyr Baydalka