Enable code coverage in Visual Studio


For some reason, every time that I want to enable code coverage for a library that I’m unit testing, I found hard to remember how to enable this fabulous feature.

Here are the steps (that work for me):

  1. Double click the [Local].testsettings file in the Solutions Items folder in the Solution Explorer window.
  2. In the "Test Settings" dialog, choose the "Data and Diagnostics" item.
  3. In the list of roles, select "Code Coverage" [Figure 1] and immediately click the ‘"Configure" button.
  4. In the "Code Coverage Detail" [Figure 2] dialog select the assemblies to instrument for code coverage.
  5. Run your test scenario and in the "Test Tools" toolbar, click the icon "Code Coverage Results".
  6. Done.

CodeCoverage1

Figure 1.

CodeCoverage2

Figure 2.

Comments (4)

  1. boutiquetoyou says:

    Enable code coverage in Visual Studio is very useful for me.

  2. Rupesh says:

    I couldn't see the Data and Diagnostics option after double clicking the test settings file…

    Could you provide some help

    Thanks in advance

    Rupesh

  3. don says:

    @aractnido

    thanks for the nice summary, short and useful!

    @rupesh

    not all versions of Visual Studion include this feature. I had to get the Ultimate Edition to use the code coverage feature

  4. Jim Evans says:

    Thanks for circling everything.  That didn't even look like a button, so my eyes never went there!  I'm getting coverage info now!