Access Keys:
Skip to content (Access Key - 0)

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 the statements which were covered by that test and which were not.

After installing dotCover and opening Visual Studio, you will notice a new menu item. dotCover integrates into four versions of Visual Studio: 2005, 2008, 2010, and 2012.

From this menu, we can execute the 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, Ctrl+L or use the dotCover| Unit Tests | Run All Tests from Solution menu to run all tests in the solution.

If ReSharper - a JetBrains .NET developer productivity tool - is installed, dotCover will integrate into the ReSharper test runner where we can hit Ctrl+U, Ctrl+L instead.

dotCover will start a new unit test session and display the results of our test run.

dotCover comes bundled with a unit test runner that it shares with ReSharper. There's one big difference: clicking the Cover Unit Tests with dotCover icon runs our tests with code coverage enabled. Once the unit tests are run with code coverage enabled, we can inspect code coverage results.

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

We can also do the inverse. If we want to learn which test covers the current method, we can run unit tests with code coverage enabled and hit Ctrl+Alt+K, T or use the dotCover| Show Covering Tests 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 selecting dotCover | Cover Startup Project launches our solution's startup project. Alternatively, Ctrl+Alt+K, K or dotCover | 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, using the Get Snapshot button. We can now inspect which lines of code were covered by our manually triggered actions.

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 using the Exclude selected node menu.

Coverage filters can also be managed through the dotCover | Edit Coverage Filters... menu or by hitting Ctrl+Alt+K, F. Filters can be defined for any solution you open or scoped to the active solution.

Once you've mastered these basics, learn the keyboard shortcuts. You can download a PDF with default keymaps from the dotCover documentation page.

Finally, don't forget to check out JetBrains TV and JetBrains .NET Tools blog for more tips and tricks with dotCover. You might also like JetBrains on Facebook or follow dotCover on twitter.

Adaptavist Theme Builder (4.2.2) Powered by Atlassian Confluence 3.5.16, the Enterprise Wiki