Welcome to EMC Consulting Blogs Sign in | Join | Help

Merrick Chaffer's Blog

Code coverage in Visual Studio 2008 using Test driven .NET and Team Coverage

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...

  1. Install Test driven .NET version 2.12.2179 from here http://www.testdriven.net/download_release.aspx?LicenceType=Personal
  2. Once installed ensure the Test driven .net addin is available from Tools, Addins in visual studio
    Picture showing addin manager
  3. 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
    Test with team coverage option
     
  4. 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.
    Output window
  5. Then click on the show coverage colour option on the test toolbar
    Show Code coverage coloring
  6. 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.
    Code coverage highlighting
  7. 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.
    Code coverage results window

     
Published 13 June 2008 14:55 by merrick.chaffer

Comments

No Comments
Anonymous comments are disabled

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems