dotCover 2017.1 Help

Getting Started with dotCover

dotCover lets us analyze how much of our .NET application code is actually being tested. By measuring method calls during unit tests or when running the application manually, dotCover shows us which statements were covered and which were not.

dotCover integrates into Visual Studio 2010, 2012, 2013, 2015, and 2017 RC. After installing dotCover with or without any other ReSharper Ultimate tools and opening Visual Studio, you will find dotCover commands under the ReSharper | Unit Tests and ReSharper | Cover in the main menu. From these menus, you can execute various commands available in dotCover.

In this topic:

Unit testing and code coverage

dotCover can run our unit tests. Various frameworks among which MSTest, NUnit, xUnit, and MSpec are supported. Hit Ctrl+T L or choose ReSharper | Unit Tests | Run All Tests from Solution in the main menu to run all tests in the solution. dotCover will start a new unit test session and display the results of our test run:

dotCover helps executing unit tests

dotCover comes bundled with a unit test runner that it shares with ReSharper. There's one big difference however: clicking Cover All Tests /help/img/dotnet/2017.1/ThemedIcon.JetBrainsDotCoverPresentationVsResourcesUnitTestingCoverageCoverAll.Screen.[Gray].png runs our tests with code coverage enabled. Once that is done, we can inspect code coverage results on the Coverage panel:

Analyzing unit test coverage with dotCover

The percentages shown are calculated based on statements in our code covered by the unit tests. In other words they show us how much of our code is actually being tested. By double-clicking we can see which lines are covered and tests pass (green), covered and tests fail (red) or uncovered (grey).


We can also navigate from covered tests in the editor. If we want to learn which tests cover the current method, we can run unit tests with code coverage, set the caret a covered statement, and hit Ctrl+Alt+K T or choose ReSharper | Cover | Show Covering Tests in the menu to find out:


Manual coverage

dotCover enables us to calculate code coverage for a specific use-case scenario. Hitting Ctrl+Alt+K P or choosing ReSharper | Cover | Cover Startup Project in the menu launches our solution's startup project under dotCover control. Alternatively, Ctrl+Alt+K K or ReSharper | Cover | Cover Application... enables us to specify the application to calculate code coverage for.


Next, we can run our application and work through a use-case scenario and tell dotCover to get a snapshot once completed. As long as the tested application runs under dotCover control, the controller dialog is displayed where you can click Get Snapshot and inspect which lines of code were covered when we worked with the tested application.


Filtering coverage results

Code coverage results can be cluttered with infrastructure code or projects that we are not interested in inspecting. We can exclude specific nodes by right-clicking them and choosing Exclude and Create Coverage Filter:

Excluding nodes from dotCover coverage results

Excluding item and creating a corresponding coverage filter will tell dotCover not to cover the item next time we run coverage analysis.

Coverage filters can also be managed through the Coverage Filters dialog (Ctrl+Alt+K F or ReSharper | Cover | Edit Coverage Filters... ). Filters can be defined for any solution you open or scoped to the active solution.

dotCover helps filtering coverage results

Once you've mastered these basics, you can learn the keyboard shortcuts or check how to work with the command-line version of dotCover.

See Also

Last modified: 3 April 2017