Code Coverage in .Net Core 2.0

孤街浪徒 提交于 2019-12-04 02:37:22

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

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

It had been a long time since this question was asked, but I think my answer below will be helpful to execute tests for the projects on .NET Core 2 and to generate coverage report using DotCover tool.

  1. Download and install Jetbrains dotcover console setup
  2. On the command line execute the command as below, which will identify the test projects in the solution and generate coverage report in HTML format. You can also generate in different formats as JSON, NDependXML or DetailedXML.

dotcover analyse /TargetExecutable:"C:\Program Files\dotnet\dotnet.exe" /TargetArguments:"test Path_To_Your_Solution_File" /Output:report.html /ReportType:HTML

You can also run and generate test coverage over .csproj file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!