Using dotCover to Cover Applications, with or without ReSharper

One of the main benefits of Code Coverage is that it allows us to detect certain areas, branches or lines of code that are not covered during a test run, which could lead to potential issues in production. We often write some code to find to our surprise that certain parts are never actually executed.

dotCover’s integration with ReSharper’s test runners, allows us to easily monitor what parts of our code are covered with tests. What happens though if we do not have tests? Whether we like it or not, there is a reality out there, and it’s mostly composed of legacy applications that have little to no knowledge of what a test is, let alone a unit test.

Although the ideal solution is to gradually add tests to existing code until we build up a good percentage of coverage, this is a process that takes time and is not accomplished overnight.

Covering Execution Paths

What dotCover allows us to do, independently of whether we have tests or not, is to execute an application and run an analysis report on what code paths of the application have actually been hit during the run. This often helps us track down not only potential issues (“I really thought that code was being executed”) but also resolve bugs (“Ah. So that’s why it’s not working”). Running Coverage of applications is a very simple process and does not even require ReSharper to be installed.

dotCover allows us to cover either an application that is currently open in a Visual Studio Project and selected as the Startup Application


or alternatively launch a non-executing Application:


And as we can see, it covers a wide variety of application types.

Covering an MVC Application

The example below outlines an execution path of the MVC Music Store application. We open the project and select Cover Startup Application from the dotCover menu. This immediately launches the application allowing us to execute a certain scenario. In our case, we will select some items and drop them in the cart.


When starting coverage, dotCover also launches the Controller Panel, which allows us to grab a snapshot of the execution at any point we are happy with it.


On clicking on Get Snapshot, the execution ends and we are returned to Visual Studio, were dotCover analyses the results and displays the Coverage Results Browser window


From here on, the possibilities of what we can do with these results are pretty much inline with that of running Code Coverage on our tests. We can examine coverage of projects, namespaces, classes and members. Navigate to a specific member as well as see in-place code coverage in the editor:


Exporting Results

New to dotCover 1.1 is the ability to export results to different formats, including XML, HTML, JSON and XML for NDepend. To export to HTML for instance, we select the Export icon from the Coverage Browser Window


and select a destination to save the output too.



Although the more common usage of dotCover and in general all coverage tools are examining coverage of our code by tests, it is also useful at time to be able to run coverage of an application during a specific scenario, for testing or diagnosis reasons. Whether or not we have ReSharper, dotCover allows us to do that easily. Also remember that dotCover ships with a Console application which does permit you to run coverage of your Unit Tests from the command line and open up the results in Visual Studio.

This entry was posted in How-To's and tagged , . Bookmark the permalink.

6 Responses to Using dotCover to Cover Applications, with or without ReSharper

  1. Sam Meacham says:

    What font are you using in that VS screenshot? Very nice…

  2. Dave says:

    How do I configure dotcover 2.0 to work with mstest runner, can it be integrated say the ms test results window ?

  3. @Dave dotCover only works with its bundled test runner (starting v2) or ReSharper test runner: both are practically the same, and both support MSTest.

  4. Dave says:

    Jura, thanks for the response, I’ll enable the resharper test runner when I want to run code coverage and use mstest runner when I don’t

    The nice thing is we use TeamCity and dotCover is integrated with it and so on the CI server we just enable it in a build step

  5. Zhiwei says:


    We want to use DotCover to collecte cover rapport for Integration Test.

    In our integration test, le test need to start some process (.exe), and eache process represent un project, all projects are inclued in one solution.

    The problem is that DotCover could get cover rapport for the launch project but not for process’s projects

    Do we need to launch process with DotCover command?


  6. Daria.Dovzhikova says:

    Can you please specify which version of dotCover you are using?

    Coverage analysis for all child processes is being collected by default.
    You can try to check the following:
    – whether PDBs for the child process are available or not,
    – does code from child process match with the coverage filters or not.

Leave a Reply

Your email address will not be published. Required fields are marked *