Code Coverage in .Net Core 2.0

How can I create 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 the latest version 2017.2.2 dotCover, which I can get on the local computer, but when the same is done in TFS Build, coverage information is not generated.

I'm not sure when the NetCore Test task in TFS will get code coverage support.

How can I publish results from DotCover to TFS to use the DotCover command line to create Coverage for .Net Core?

+9
source share
3 answers

The VSTest task cannot run .NET kernel tests because it uses the test platform version 1. To run basic kernel tests, we recommend using the basic .NET task (preview) using the test command.

However, code coverage and other data collection are not supported , but agent support is not available.

We fix this issue as part of this https://github.com/Microsoft/vsts-agent/pull/1149/files The thread will be updated after the fix disappears and the new agent will be released. thread https://github.com/microsoft/vstest/issues/579#issuecomment-324401462

Source link: VSTest task cannot run tests in .NET Core 2.0 test project

+2
source

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

Just add it to your test project:

 dotnet add package coverlet.msbuild 

And run it along with dotnet test as a parameter:

 dotnet test /p:CollectCoverage=true 

Supported Formats:

  • JSON (default)
  • lcov
  • opencover
  • Cobertura

I made a more detailed implementation about it here: .Net Core Unit Test and code coverage using Visual Studio Code

+5
source

It has been a long time since this question was asked, but I think that my answer below will be useful for performing tests for projects on .NET Core 2 and for creating a coverage report using the DotCover tool.

  • Download and install the configuration of your Jetbrains Carrier.
  • At the command prompt, run the command as shown below, which identifies the test projects in the solution and generates a coverage report in HTML format. You can also create in different formats like JSON, NDependXML or DetailedXML.

Point Analysis / 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 on top of the .csproj file.

0
source

Source: https://habr.com/ru/post/1271539/


All Articles