hi. I’m Menelaos

Curious mind. Careful builder.

I build things that help people, and I spend time with ideas that last.

Code Coverage in Visual Studio

A Complete Guide to Measuring What Your Tests Really Cover

Oct 18, 2025

When you spend hours writing automated tests, a question inevitably arises:

“How do I know if my tests actually test the right code?”

That’s where code coverage comes in.

In this post, we’ll explore why code coverage matters, the different ways to enable it in Visual Studio, and the best setup for .NET developers, including how to use Coverlet, ReportGenerator, and Fine Code Coverage effectively.


Why Code Coverage Matters

Code coverage measures how much of your source code is executed when you run your automated tests.

The metric is usually expressed as a percentage. For example, 75% means three-quarters of your code runs during tests.

But coverage isn’t just a vanity number. It helps you:

  • Identify untested logic: Find branches, exceptions, and corner cases that your tests miss.
  • Improve code quality: Encourage modular, testable design.
  • Prevent regressions: If a bug appears in uncovered code, you know where to focus your next tests.
  • Track test health over time: Coverage trending downward can signal risky changes or missing tests.

That said, 100% coverage doesn’t guarantee quality.

A poorly written test can “touch” a line without verifying anything useful. Coverage should be seen as a guide, not a goal.


Code Coverage Options in Visual Studio

There are several ways to enable and visualize code coverage in Visual Studio. Let’s explore the main ones and what makes each unique.

  1. Visual Studio Enterprise Built-In Coverage

If you’re using Visual Studio Enterprise, you already have built-in support for code coverage.

Pros:

  • No setup required.
  • Integrated into Test Explorer.
  • Great for quick overviews.

Cons:

  • Only available in Enterprise edition.
  • Reports are basic, only limited filtering and export options.
  • Doesn’t easily integrate with CI pipelines.

If you’re a professional developer working on a team or open-source project, you’ll likely prefer Coverlet or Fine Code Coverage for more flexibility.

2. Coverlet + ReportGenerator

Coverlet is the most popular open-source code coverage tool for .NET, it handles the heavy lifting of measuring which lines of code your tests execute

It integrates seamlessly with dotnet test, Visual Studio, and CI pipelines like GitHub Actions or Azure DevOps.

ReportGenerator transforms the raw coverage data into clean, detailed HTML reports with color-coded summaries, class-level insights, and visual graphs.

Together, they provide a flexible, CI-friendly, and fully open-source solution that works seamlessly across test projects and environments.

3. Fine Code Coverage

Fine Code Coverage (FCC) is a Visual Studio extension that brings real-time, in-IDE visibility to your code coverage.

Instead of generating external reports, FCC integrates directly into your workflow, showing line-by-line coverage highlights and percentage indicators right inside the editor. It uses Coverlet under the hood, but automates the setup and visualization — making it ideal for developers who want immediate feedback without leaving Visual Studio.

With FCC, you can quickly see which parts of your code are tested and which need more attention, streamlining the test-writing process.

Coverlet vs. Fine Code Coverage

FeatureCoverletFine Code Coverage
InstallationNuGetVS Extension
Works in CI✅ Yes⚠️ No (IDE only)
Visual Studio IntegrationManualAutomatic
OutputXML, JSONHTML + in-editor colors
Customizable✅ Highly⚙️ Limited

Best combo:

Install Coverlet in your test project for CI + automation,

and use Fine Code Coverage in Visual Studio for local visualization.


Setting Up Code Coverage with Coverlet

You can install Coverlet as a NuGet package to your test project:

dotnet add \<YourTestProject> package coverlet.collector
Tip: You only need to install it in one test project if you want to measure coverage across multiple projects, as long as those tests reference the same assemblies.

Running Tests with Coverage

Once installed, you can run coverage in several ways:

Option 1: From Visual Studio Enterprise edition (not working in community/professional)

If you just press Run Tests in Visual Studio, coverage data will not appear automatically.

To see it:

  • Open Test Explorer.
  • Choose “Run > Analyze Code Coverage for All Tests.”
  • Wait for the run to complete.
  • The Code Coverage Results window will appear.

Option 2: From the Command Line

Use the following command to collect coverage data: dotnet test --collect:"XPlat Code Coverage"

This creates a file like: TestResults/123abc/coverage.cobertura.xml

You can use this file to feed it to a CI or view it with ReportGenerator, see next section on how to do that.

Option 3: Running Tests with Coverage (Fine Code Coverage + Coverlet)

If you install both:

  • The Fine Code Coverage (FCC) Visual Studio extension, and
  • The coverlet.collector NuGet package in your test project,

you get the best of both worlds:

  • Coverlet does the actual work of measuring code coverage (the collector),
  • FCC automatically triggers it every time you run your tests in Visual Studio, and
  • FCC shows the results directly inside the IDE. There is no need to run commands or open external reports.

Generating Human-Readable Reports

You can use ReportGenerator to transform raw coverage files into beautiful HTML reports:

dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coveragereport"

Then open the index.html file in your browser.

You’ll get:

  • Line-by-line colored coverage visualization
  • Branch and method-level stats
  • Trend graphs (if you compare runs)

Visualizing Coverage with Fine Code Coverage (FCC)

Fine Code Coverage is a Visual Studio extension that automatically collects and visualizes coverage results inside the IDE.

Installation:

  1. Go to Extensions > Manage Extensions.
  2. Search for “Fine Code Coverage”.
  3. Install and restart Visual Studio.

How it works:

  • FCC uses Coverlet under the hood.
  • It runs coverage every time you run your tests.
  • You’ll see a color overlay in your code editor:
    • ✅ Green: covered lines
    • ⚠️ Orange: partially covered
    • ❌ Red: not covered

You can also view detailed project-level summaries and export HTML reports.

Why FCC is great:

  • Instant feedback inside Visual Studio.
  • No need to configure CLI or manual report generation.
  • Works with all editions of Visual Studio, including Community.

What to Measure and What Not To

It’s easy to get lost chasing numbers. Instead, focus on meaningful metrics: Measure:

  • Core logic (business rules, calculations)
  • Critical paths (security checks, data validation)
  • Error handling (exceptions, fallbacks)

Don’t obsess over:

  • DTOs and models
  • Auto-generated code
  • Trivial getters/setters

You can exclude these from coverage with filters like:

<PropertyGroup>
<ExcludeByFile>**/Migrations/*.cs;**/Generated/*.cs</ExcludeByFile>
</PropertyGroup>

Advanced Configuration Tips

  1. Merge Multiple Projects If you have several test projects, you can merge their coverage:
dotnet test --collect:"XPlat Code Coverage" --results-directory:"TestResults"
reportgenerator -reports:"TestResults/**/coverage.cobertura.xml" -targetdir:"coveragereport"
  1. Include/Exclude Filters Use filters to target specific assemblies:
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[MyApp.*]*"

Or exclude libraries:

-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*.Tests]*"

CI/CD Integration

Coverlet integrates seamlessly with:

  • GitHub Actions
  • Azure Pipelines
  • Jenkins
  • GitLab CI

You can automatically generate and publish reports in your CI pipeline, for example:

- name: Test and collect coverage
run: dotnet test --collect:"XPlat Code Coverage"
- name: Generate report
run: reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coveragereport"

Summary: The Ideal Setup

EnvironmentRecommended ToolWhy
Local developmentFine Code CoverageVisual feedback in the editor
Continuous IntegrationCoverlet + ReportGeneratorAutomated reports, machine-readable
Large team/projectCombine bothDevelopers see instant feedback + CI stores history

Final Thoughts

Code coverage is one of the most valuable tools in a developer’s toolkit. It gives you objective feedback on how much of your codebase is tested, helps you discover dead or untested logic, and encourages better design and testability.

Chasing 100% code coverage is rarely realistic or even beneficial. Some code paths (like logging, configuration, or defensive error handling) aren’t worth testing in isolation. What matters most is meaningful coverage. Ensuring that your business logic, critical workflows, and edge cases are validated through robust tests. High-quality tests that verify behavior are far more valuable than tests that merely increase the coverage percentage.

Whether you use Visual Studio Enterprise, Fine Code Coverage, or the Coverlet + ReportGenerator combo, choose the approach that best fits your workflow. The goal isn’t just to see green bars, it’s to build confidence that your code works, stays stable through changes, and can grow safely over time. Of course, let’s be honest: those green bars do look pretty satisfying!

Tags