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.