This article lists and explains all Microsoft.Testing.Platform extensions related to the code coverage capability.
You can use the code coverage feature to determine what proportion of your project's code is being tested by coded tests such as unit tests. To effectively guard against bugs, your tests should exercise or cover a large proportion of your code.
Microsoft code coverage
Microsoft Code Coverage analysis is possible for both managed (CLR) and unmanaged (native) code. Both static and dynamic instrumentation are supported. This extension is shipped as part of Microsoft.Testing.Extensions.CodeCoverage NuGet package.
Note
Unmanaged (native) code coverage is disabled in the extension by default. Use flags EnableStaticNativeInstrumentation and EnableDynamicNativeInstrumentation to enable it if needed.
For more information about unmanaged code coverage, see Static and dynamic native instrumentation.
Important
The package is shipped with Microsoft .NET library closed-source free to use licensing model.
For more information about Microsoft code coverage, see its GitHub page.
Microsoft Code Coverage provides the following options:
Option
Description
--coverage
Collect the code coverage using dotnet-coverage tool.
--coverage-output
The name or path of the produced coverage file. By default, the file is TestResults/<guid>.coverage.
--coverage-output-format
Output file format. Supported values are: coverage, xml, and cobertura. Default is coverage.
For more information about the available options, see settings and samples.
Note
The default value of IncludeTestAssembly in Microsoft.Testing.Extensions.CodeCoverage is false, while it used to be true in VSTest. This means that test projects are excluded by default. For more information, see Code Coverage configuration.
Coverlet
Important
The coverlet.collector NuGet package is designed specifically for VSTest and cannot be used with Microsoft.Testing.Platform.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET
feedback
.NET
is an open source project. Select a link to provide feedback:
Start testing your C# apps by using the testing tools in Visual Studio. Learn to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.