Scott Dorman

ephemeral segment

  Home  |   Contact  |   Syndication    |   Login
  603 Posts | 10 Stories | 862 Comments | 51 Trackbacks

News


Post Categories

Image Galleries


Microsoft Store


Creative Commons License



Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

View blog authority

Add to Technorati Favorites

Windows Live Alerts

AddThis Social Bookmark Button

LinkedIn profile

Community Credit profile

The Code Project

Follow me on Twitter

Get Free Shots from Snap.com

Community Credit Hall of Fame

Get Feedghost

Xobni outlook add-in for your inbox



Support This Site

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

I have been writing a lot of unit tests lately using Microsoft Test. This included converting a bunch of old NUnit tests to the MS Test format, which was relatively painless. While examining the code coverage results (after all, what good are unit tests if you don’t know what portions of the code are being tested and not tested), I have noticed that the results sometimes lie.

For example, I have a class that contains some extension methods for manipulating enums. One of those methods takes an enum and coverts it to an IList of KeyValuePairs containing the enum value and a description.

image

As you can see by the highlighted row in the code coverage results window, the ToList() method is only covered at 90.91% and there are 2 blocks that aren’t covered. At first glance, this looked reasonable so I reviewed the actual ToList() method with code coverage highlighting turned on.

image

What’s wrong with this picture? I’m using the default code coverage highlighting colors, so the light blue coloring indicates 100% coverage. Knowing that, I’m seeing a method that is colored as being 100% covered yet the coverage results are showing it as a different number.

This stays consistent no matter how many times I re-run the tests and I have also seen it on other methods in other classes.

Technorati Tags: , ,
DotNetKicks Image
posted on Saturday, January 17, 2009 12:30 PM

Feedback

# re: Microsoft Test and Code Coverage 1/17/2009 11:47 PM Mark Flory
Scott,

I am not 100% sure but I have a spectulative guess. Since a block of code is to my understanding really a potential pathway throught the code it is possible you are not testing that the code with an empty enum.

That may sound crazy but my gut tells me that is right.

# re: Microsoft Test and Code Coverage 4/13/2009 2:22 PM Jonathan Harley
Hey Scott,

I'd try a different coverage analyzer and see if it's not just a limitation of the tool.

There are a couple of free ones out there, the best of which (most mature at least) is NCover Community Edition (ncover.com).

Plus, you don't have to instrument your code..

-- Jonathan

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: