Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Coverage in .Net Core 2.0

How can I generate code coverage in .Net Core 2.0?

I tried the following:

"TestPlatform\vstest.console.exe" --collect:"Code Coverage"

But I got this error message:

Data collector 'Code Coverage' message: Cannot find CodeCoverage.exe.

I tried dotCover latest version 2017.2 which I am able to get the coverage on the local machine, but when the same is run in the TFS Build no coverage information is generated.

I am not sure when NetCore Test task in TFS will get support for code coverage.

How can I publish the results from DotCover in TFS also, to use DotCover Commandline to generate the Coverage for .Net Core?

like image 840
samdinesh Avatar asked Sep 05 '17 14:09

samdinesh


2 Answers

Coverlet is a cross platform code coverage available as NuGet package.

Just add it on your test project:

dotnet add package coverlet.msbuild

And run it altogether with dotnet test command as parameter:

dotnet test /p:CollectCoverage=true

Supported Formats:

  • json (default)
  • lcov
  • opencover
  • cobertura

I made more detailed implementation about it here: .Net Core Unit Test and Code Coverage with Visual Studio Code

like image 175
equiman Avatar answered Sep 18 '22 22:09

equiman


VSTest task cannot run .NET core tests as it uses the Test platform version 1. To run .NET core tests, we recommend using the .NET core task(preview) with the test command.

However, Code coverage and other data collection is not supported yet, no agent support.

We are fixing this issue as part of this https://github.com/Microsoft/vsts-agent/pull/1149/files Will update the thread once fix is gone and new agent is released. thread https://github.com/microsoft/vstest/issues/579#issuecomment-324401462

Source Link: VSTest task fails to execute tests in .NET Core 2.0 test project

like image 26
PatrickLu-MSFT Avatar answered Sep 19 '22 22:09

PatrickLu-MSFT