Code coverage while debugging in Visual Studio

test code 21 Reputation points
2025-09-11T10:38:51.94+00:00

I am looking for a tool that can measure and show code coverage while I am debugging my application inside Visual Studio. Ideally, I’d like to be able to step through code in a debug session and see coverage information at the same time.

I have been exploring different code coverage tools, but most of them seem to require creating and running test cases in order to measure coverage.

For example, I tried Fine Code Coverage and Visual Studio’s built-in code coverage. Both of these integrate with unit testing frameworks, which means I need to write and execute test cases before I can see any coverage results.

I also checked OpenCover. Unlike the others, OpenCover does not require writing test cases directly. Instead, it needs to be provided with an executable, and then it tracks which parts of the code are executed when that program runs. While this is useful, it still requires running the application separately.

I am looking for a tool which will let me step through code in a debug session and see coverage information without having to create unit tests or generate separate executables just for coverage.Does a tool which does code coverage while debugging exist? If so, could you please suggest one?

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Umair ali raza Umair ali raza 15 Reputation points
    2025-09-11T12:33:03.1433333+00:00

    True debug-time code coverage (seeing coverage while stepping in the debugger) is rare. Most tools, like Visual Studio, Fine Code Coverage, or OpenCover, require running tests or the app separately.

    Closest options:

    JetBrains dotCover: attach to a running process; shows which lines execute.

    NCrunch (paid): continuously monitors code and displays coverage in the editor almost in real-time.

    OpenCover / Coverlet: free, but coverage appears after running the app, not while stepping.

    In short: no free tool perfectly overlays coverage while debugging line by line, but dotCover or NCrunch are the closest practical solutions.

    1 person found this answer helpful.

  2. Adiba Khan 895 Reputation points Microsoft External Staff
    2025-10-01T10:52:05.7766667+00:00

    Thanks for reaching out.

    ·         Visual studio’s built-in Code coverage only works when executing unit tests, not during interactive debugging.

    ·         Tools like Open Cover and Fine Code Coverage reply on test execution, not manual debugging.

    ·         Currently, there is not a Visual Studio supported tool that shows live coverage while stepping through code in a debug session.

    Recommended approach:

    ·         Use unit tests + code coverage tools (Fine Code Coverage, Visual studio Enterprise’s coverage, Coverlet , OpenCover).

    ·         For runtime tracing, developers might need profiling or instrumentation tools (but those aren’t true “coverage while debugging”).

    Reference Link:

    ·         Determine code testing coverage - Visual Studio (Windows) | Microsoft Learn

    ·         Use code coverage for unit testing - .NET | Microsoft Learn

    ·         Microsoft.Testing.Platform Code Coverage extensions - .NET | Microsoft Learn

    ·         dotnet-coverage code coverage tool - .NET CLI - .NET | Microsoft Learn

    ·         Customizing Code Coverage Analysis - Visual Studio (Windows) | Microsoft Learn

    ·         GitHub - coverlet-coverage/coverlet: Cross platform code coverage for .NET

    ·         Use code coverage for unit testing - .NET | Microsoft Learn

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.