I am working on a .net core 2.0 project. With the latest version of Visual Studio agent, I can collect the code coverage with a command like below:
"C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" /framework:".NETCoreApp,Version=v1.1" /collect:"Code Coverage" "G:\tmp\trial\bin\Debug\netcoreapp1.1\trial.dll
The command generates a .coverage file which can be opened in Visual Studio. But how can I publish the result in vsts? It seems the Publish Code Coverage task of vsts doesn't understand this file.
The Publish Code Coverage task only supports Cobertura and JaCoCo output.
See this thread and comment for details on using the Visual Studio Test task to generate and publish the code coverage.
@pjquirk I managed to get it work by following the thread you mentioned. Thanks.
I have generated .coverage file using vstest.console.exe and also I have exported the xml file by opening and exporting .coverage file. The final exported file contains .coveragexml extension, and this is xml file basically which has all the details of the tests and coverage report with source code linkgae.
How can I consume these files(.coverage, .coveragexml) in JACOCO plugin on Jenkins so that I can show the source code to users which got covered by unit tests.
I have tried EMMA plugin on generated .coveragexml file but it doesn't display source code, it just displays the overall result of failed/passed test cases.
@aashish2384 Can you please create a separate issue for this for better tracking?
It is funny that M$ VSTS does not support M$ VS coverage report publishing but supports Java counterparts. Way to go Microsoft. Solid logic there
@pjquirk Maybe I'm blind, but I don't see anywhere in that thread where it says how to convert a *.coverage file to a JaCoCo file (as required by VSTS). Could you explain it here?
@aashish2384 Are you converting the .coverage to a .coveragexml within the DevOps pipeline? How are you doing this?
@joshmouch If you're already generating a .coverage file via VSTest, you just need to use the _Visual Studio Test_ task to run your tests and publish the coverage (by checking the "Code Coverage Enabled" box). The _Publish Code Coverage_ task is really only for third party coverage files.
I've responded to this on another thread but, pasting here for searchability:
If that's true then the code coverage screen is pretty limited, correct? This is what Resharper tells me is covered:
And this is all I see on the DevOps screen. First, the 50% is wrong...
... then when I click on the "Code Coverage succeeded" header, it takes me to the "Code Coverage" tab, which only has a download link and no useful reports.
I think I've come to the conclusion that the push here is to use a third party tool for the code coverage results. I've also run across a nuget package called Coverlet which is supposed to convert ".coverage" binary files to xml, so I'll give that a go.
for those still using old version of TFS. I found the Task "Publish Test Results" will publish the .trx files and if you go to advance and select upload Test Attachments, it will also upload your code coverage files.
You may need to do some additional work on excluding test .dll and various other dll with your runsettings file. edit sadly I do not know how to get TFS to combine Code Coverage from different project test runs.
Future readers, this SOF answer might help.
a few bread crumbs
"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/gtest-coverage.xml -targetdir:./TestResults -reporttypes:cobertura
now you have a cobertura.xml file you can digest
Most helpful comment
It is funny that M$ VSTS does not support M$ VS coverage report publishing but supports Java counterparts. Way to go Microsoft. Solid logic there