Show Covering Tests with dotCover

One of the new features dotCover has added is the ability to find tests that cover a certain piece of code. Something remotely similar has been available in ReSharper, although it has been kind of an archaic solution (i.e. Find Usages on Method calls, locate Test assemblies in Result window).

dotCover makes this easier by providing quick access to this information and extends it in functionality.

Below we can see some tests from an MVC application. Let’s run Code Coverage on it using dotCover first.

image

Now let’s switch over to the Source Code and select some random source code, in this case the MembershipService.ChangePassword line in the ChangePassword action:

image

In order to see the tests that cover this line of code, we can either press the default key combination of Ctrl+Alt+K or select the option Show Covering Tests from the dotCover:

image

dotCover will then display a small window showing all the different tests that cover that line of code.

image

At this point, we can run the selected tests or add them to the existing ReSharper Test Runner session. This allows us to easily jump from specific sections of code to the corresponding tests and execute them instantly.

One minor note: The default key mapping conflicts with KeePass, but you can easily re-assign it via Visual Studio Tools | Options | Keyboard, or do as I did and change KeePass to Ctrl+Alt+P (P as in Password…makes more sense).

SNAGHTML5841541

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

10 Responses to Show Covering Tests with dotCover

  1. Joe White says:

    Do you have to run the tests in the ReSharper GUI test runner in order to gather the coverage data to support this feature? Or can it load the results of a command-line run?

    We have a lot of regression tests — they take about fifteen hours to run, in total (though we spread them out over many build machines, so we typically get feedback on each subset in two or three hours). If it would be possible to gather coverage data as they run, aggregate those multiple files together somehow, access them from one of our development machines, and instantly be able to see which regression tests run a particular line of code (or did as of the last continuous build)… well! That would be a *sweet* feature.

    On the other hand, if I have to run the tests with coverage *in the ReSharper runner* before I can do this right-click “Show covering tests”, then this would really only be useful to us for our (fast) unit tests, and not for our (slow) regression tests. Which would be too bad, because even without a tool, it’s much easier to tell which *unit* tests would touch a given piece of code — that’s often just a matter of naming convention. The regression tests are where this would be really useful.

    Another question: does this feature bog down when you have lots of tests? We have over 15,000 automated tests — is “Show covering tests” able to run quickly with that amount of coverage data?

  2. hhariri says:

    @Joe,

    It’s not necessary to have the ReSharper test runner to use dotCover. We will be shipping version 1 with a Console runner that you can use in a Continuous Integration environment and in the future we’ll be providing a more integrated option with TeamCity.

    Regarding the amount of tests, I can’t tell you exactly how it will perform with 15.000 but it would be great if you could maybe try it out and let us know your feedback. We’d love to know the results.

  3. Chris Holmes says:

    It reports 0% code coverage when using BDd style tests with the StructureMap/RhinoMocks AutoMocker.

    Example: Using the AutoMocker, I make a call like: ClassUnderTest.Handle(new MyMessage());

    This clearly executes the code in my class and exercises it in the test harness. The Code Coverage tool doesn’t detect it as ever calling the Handle(MyMessage message) method.

    I’ll be interested in buying this when it fully works. I love using code coverage as a guide to tell me when I am missing gaps in my testing.

  4. Hadi Hariri says:

    @Chris

    If you could please log the issue at http://youtrack.jetbrains.net along with a sample project we’ll be sure to look at it.

  5. andrewmbourne says:

    resharper 6 and dot cover 1.1.1 or 1.2,

    I have no option to show covering tests, the default key stroke ctrl alt k, has no effect.
    I have also changed the key combination, and still this does not work. There is no option for show covering testing in the dotcover menu.

    Cheers.

  6. Hadi Hariri says:

    @Andrew

    Can you please check the key bindings in the Options menu of Visual Studio?

  7. andrewmbourne says:

    @Hadi

    Yes in ToolsOptionsEnvironmentKeyboard I have the key binding for
    dotCover.DotCover_ShowTestsCoveringContext set to Global Ctrl+Alt+C

    Cheers A.

  8. James World says:

    I have the same problem; no show covering tests option – and key is correctly mapped. Just download and installed the latest version today.

  9. James World says:

    I’ve been playing around with this…
    Removing the .NET Reflector integration solves the problem… yet another .NET Reflector/Jetbrains clash!
    Not a solution however, just a workaround…

  10. andrewmbourne says:

    I can confim that the workaround suggested by james works.

    Cheers, however would be nice to have this issues fixed.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>