I have a large .NET Framework solution and want to start collecting code coverage data as part of our build pipeline (as well as on our local developer machines).
On the Coverlet GitHub page it says that it supports .NET Framework projects but all the examples are using the dotnet test
CLI command.
Is it possible to use Coverlet for this or should I be looking at something like OpenCover?
Cobertura Plugin for the code coverage data.
Coverlet is an open source project on GitHub that provides a cross-platform code coverage framework for C#. Coverlet is part of the . NET foundation. Coverlet collects Cobertura coverage test run data, which is used for report generation.
The first step is to head to the Extensions menu and select Manage Extensions. Then, search Run Coverlet Report and install it - you have to close all Visual Studio instances to install it.
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
dotnet test --collect:"XPlat Code Coverage"
Option 1
Use the task Visual Studio Test
Create a .runsettings file and configure Coverlet in the .runsettings (see https://github.com/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md#coverlet-options-supported-by-vstest-integration)
Reference the .runsettings file in the task
Tick the option Code coverage enabled
If this doesn't work, use a Publish code coverage results
task, to publish the corbertura file (default name: coverage.cobertura.xml
) produced by the test task
Option 2
<PropertyGroup>
<VSTestTaskAssemblyFile>$(MSBuildThisFileDirectory)\..\packages\Microsoft.TestPlatform.Build.16.6.1\lib\netstandard2.0\Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile>
<VSTestConsolePath>$(MSBuildThisFileDirectory)..\packages\Microsoft.TestPlatform.Portable.16.6.1\tools\netcoreapp2.1\vstest.console.dll</VSTestConsolePath>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
</PropertyGroup>
MSBuild
task
<your-project>.csproj /p:CollectCoverage=true /t:VSTest
Publish code coverage results
task to publish the corbertura file (default name: coverage.cobertura.xml
) produced by the MSBuild
taskIf 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