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. After installing dotCover with or without any other ReSharper Ultimate tools and opening Visual Studio, you will find dotCover commands under the and in the main menu. From these menus, you can execute various commands available in dotCover.
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 unit test session and display the results of our test run:in the main menu to run all tests in the solution. dotCover will start a new
dotCover comes bundled with a unit test runner that it shares with ReSharper. There's one big difference however: clicking Cover All Tests runs our tests with code coverage enabled. Once that is done, we can inspect code coverage results on the Coverage panel:
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 in the menu to find out:
dotCover enables us to calculate code coverage for a specific use-case scenario. Hitting Ctrl+Alt+K P or choosing launches our solution's startup project under dotCover control. Alternatively, Ctrl+Alt+K K or enables us to specify the application to calculate code coverage for.in the menu
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 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 ). Filters can be defined for any solution you open or scoped to the active solution.