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.
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.
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.
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 .
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
"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"
"ReportGenerator_4.4.7\net47\ReportGenerator.exe" -reports:./TestResults/coverage.xml -targetdir:./TestResults -reporttypes:cobertura
post {
always {
cobertura coberturaReportFile: './TestResults/Cobertura.xml'
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With