A colleague of mine this week showed me his code coverage as being over 94% for his production code, which impressed me so much, it spurred me on to ensure that all code paths in my code from now on go blue instead of red when testing with Team coverage, using the Test driven .NET addin for visual studio 2008. Not sure what I'm on about, then follow the steps below to get up to speed...
- Install Test driven .NET version 2.12.2179 from here http://www.testdriven.net/download_release.aspx?LicenceType=Personal
- Once installed ensure the Test driven .net addin is available from Tools, Addins in visual studio
- In your unit test files, simply click anywhere outside of a code block, and select the Test with -> Team coverage from the right click context menu
- Keep an eye after the tests have run on the output window, as the test results window will not actually be updated by running this context menu option, so you'll need to look here to see how many of your tests actually passed.
- Then click on the show coverage colour option on the test toolbar
- Now you will see what areas of your code are covered. Blue background is covered, orange is partially covered (this is like when you have a two condition if statement and the unit test has only satisfied on of the conditions to get passed it), and red is not covered at all.
- Another option for a summary view is to look at the Code Coverage Results window which should appear after the unit testing is complete, and sort by any of the column headers, or simply drill down to the code you wrote to see if it is covered fully. In the example below you'll see that I had 91.67% coverage on the code I wrote, anything over 90% is pretty good going in my opinion.