cd /news/developer-tools/code-coverage-net · home topics developer-tools article
[ARTICLE · art-11448] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Code Coverage .NET

The article explains two primary methods for generating code coverage in .NET projects: using the built-in "XPlat Code Coverage" collector with `dotnet test --collect:"XPlat Code Coverage"`, or using the Coverlet MSBuild integration with `dotnet test /p:CollectCoverage=true`. After generating a Cobertura XML coverage file, developers can install and use the ReportGenerator tool to create an HTML report by running `reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport`. Coverlet is noted as the more common approach in real .NET projects because it integrates well with CI/CD pipelines and allows setting coverage thresholds that can fail the build if coverage drops below a specified percentage.

read1 min views23 publishedMay 23, 2026

For .NET projects, the most common manual way is using: coverlet dotnet test --collect:"XPlat Code Coverage" Simplest first: dotnet test --collect:"XPlat Code Coverage" After running, you’ll see something like: Attachments: .../coverage.cobertura.xml That XML file contains the coverage result. Then install the report generator globally: dotnet tool install -g dotnet-reportgenerator-globaltool Generate an HTML report: reportgenerator -reports:**/coverage.cobertura.xml -targetdir:coveragereport Then open: coveragereport/index.html You’ll see: Typical enterprise flow: dotnet test

-> code coverage
-> stryker mutation test
-> CI/CD quality gate
dotnet test --collect:"XPlat Code Coverage"

or dotnet test /p:CollectCoverage=true Then open: coveragereport/index.html Coverlet is the more common approach in real .NET projects now because it integrates nicely with CI/CD and gives flexible reporting. Here’s the normal flow. Inside your test project folder: dotnet add package coverlet.msbuild This adds the MSBuild integration of Coverlet. dotnet test /p:CollectCoverage=true After running, you’ll see something like: +--------+------+--------+--------+ | Module | Line | Branch | Method | +--------+------+--------+--------+ and a generated file: coverage.json Usually we use Cobertura format: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura Then generate HTML: reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport Open: coveragereport/index.html Whenever code changes: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura then:

reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport
Built-in collector:
dotnet test --collect:"XPlat Code Coverage"

Coverlet MSBuild: dotnet test /p:CollectCoverage=true Both are valid. But Coverlet gives: Example threshold: dotnet test /p:CollectCoverage=true /p:Threshold=80 This FAILS the build if coverage goes below 80%.

── more in #developer-tools 4 stories · sorted by recency
── more on @.net 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/code-coverage-net] indexed:0 read:1min 2026-05-23 ·