Make sure you edit the same test settings that you use in Visual Studio 2010

I will show below hot to enable Code Coverage in Visual Studio 2010, how to view the results and also how to avoid a strange pitfall that I myself fell into.

Just spent the better part of an hour trying to figure out how to get the code coverage results in Visual Studio 2010. Eventually I found out that there was no problem at all. The issue was that I had edited one set of test settings and ran my tests on another set of test settings.

Update: I solved this issue and the reason for there being two different default sets of test settings The Reason for the different test settings in Visual Studio 2010

ActiveTestSettings

Don’t make this mistake it will cost you time!

(More details below:)

OK – still reading? Good… Here is the detailed description

In Visual Studio 2008 there is by default only one set of test settings called “Local”. This is not the case in Visual Studio 2010. I have searched but not found the reason for this. All I can do right now is note that this is the case and get back to you when I find out why?

The default Visual Studio 2010 test project creates two sets of test settings: “Local” and “Trace and Test Impact”. I have no clue what the latter test settings are used for but naturally this caused me a problem.

If there is a way to get it wrong – you will! ;~)

I selected “Edit Test Settings” (see picture above) and edited my test settings to enable Code Coverage.

Note: This is done under “Execution Criteria” –> (expand the window to show Collectors) –> Collectors –> Code Coverage –> (Check Enabled) –> Advanced –> in Code Coverage Detail select the “Artifacts to instrument” –> Ok –> Apply.

Then I ran my tests. Nothing happened! I didn’t get any Code Coverage Results (Test –> Windows –> Code Coverage Results)!

After pulling my hair, drinking too much espresso and searching for how to enable testing in Visual Studio 2010 without finding the answer I suddenly stumbled upon it:

Next to the Edit Test Settings menu option under Test there is another option “Select Active Test Settings”. Naturally since there were two (default) options I had edited the one set of settings and executed using the other!

Doh! One hour down the drain!

Now you know how to do it. Don’t repeat my mistake. And if you know why there are two default sets of test settings in Visual Studio 2010, please, let me know!

Cheers,

M.

This work is licensed under a Creative Commons license.

posted @ Monday, June 22, 2009 4:56 PM

Print

Comments on this entry:

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by Michael Laterza at 12/30/2009 6:06 PM
Gravatar
I don't see any "Execution Criteria" option. The only way I can enable the Code Coverage checkbox is under the "Data and Diagnostics" option. Even after enabling it under local settings and making sure I selected the same option under "Select Active Test Settings" I still get this error message when trying to view the "Code Coverage" window:

Cannot find any coverage data (.coverage or .coveragexml) files. Check test run details for possible errors.

I'm still trying to find out how to view Code Coverage data in VS 2010...

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by Sebastien Chedal at 2/11/2010 3:55 PM
Gravatar
Hi, i had the same problem even if i worked on the correct test settings set.
and i after trying and trying, i did it.. i don't know why. it seems to happens when i make a test->run->Test in current context.
But now when i reopen my solution it works even if i choose run all tests in solution wich didn't generate coverage before...

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by Jason at 4/16/2010 6:18 PM
Gravatar
Also note you need to 'configure' code coverage (specify which assemblies to instrument. You do this on the data & diagnostics tab:
* Select code coverage in the list
* Make sure it's selected
* Click the configure button and select assemblies to test coverage values.

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by Mohamed Radwan at 5/30/2010 10:40 PM
Gravatar
Thank you so much, it works with me but of course there is no Execution Criteria, maybe this was in beta, so for Michael Laterza, all you have to do is double click Code coverage and choose your project assembly and it will work

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by Mohamed Radwan at 5/31/2010 9:18 PM
Gravatar
Thank you so much, it works with me but of course there is no Execution Criteria, maybe this was in beta, so for Michael Laterza, all you have to do is double click Code coverage and choose your project assembly and it will work

# re: Make sure you edit the same test settings that you use in Visual Studio 2010

Left by TubeHome at 7/23/2010 1:40 PM
Gravatar
Visual Studio rules...

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 8 and type the answer here:
 

Live Comment Preview: