How Is Code Coverage Assessed?

Learn how to measure code coverage with xUnit tests.

There are several ways of collecting code coverage metrics while running .NET tests. One common method is to install the coverlet.collector NuGet package in the test project. This package already comes preinstalled if we use the default xUnit project template.

The following playground demonstrates how the coverlet.collector collects the coverage metrics. The NuGet package reference is on lines 19–22 of the MainApp.Tests.csproj file.

Get hands-on with 1200+ tech skills courses.