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
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.
posted @ Monday, June 22, 2009 4:56 PM