Sunday, October 31, 2010

How to enable code coverage in Visual Studio 2010

This is how you enable code coverage for a solution in Visual Studio 2010:

1. In the top menu, choose "Test" and then "Select Active Test Settings". Make sure "Local" is selected.
2. Go to the top menu again, choose "Test" and then "Edit Test Settings". Choose "Local". The "Test Settings" window will now be shown.
3. Choose "Data and Diagnostics".
4. Under "Data and Diagnostics for selected role:", select "Code Coverage" by checking the "Enabled" box. Then click on the button "Configure" just above the grid. The Code Coverage Detail window will now be shown.
5. Select the assemblies/DLLs that you want to run code coverage on, then click "OK".
6. Click "Apply" then "Close".

After running tests the code coverage results should now be shown in the "Code Coverage Results" window.