Monday, February 06, 2006 - Posts

Visual Studio 2005 Code Coverage doesn't handle C# switch very well

It's surprising to me that, so far, I haven't been able to find any blog entry or article anywhere about why the Visual Studio 2005 Code Coverage tool doesn't handle C#'s switch statement properly.

I use switch a lot, because it's so much easier to read than lots of if/else ifs, but the fact is any function in my code that contains switch gets marked, after complete and utter unit-testing, as not having been covered 100% -- there's always one block counted as being untested. Yet every line of code in that function is marked nicely in light blue, indicating that it was run. The unit test code makes sure that all cases are covered...

Then when I rewrite the code to use if/else if/... instead of switch, coverage is 100%.

Duh! I want to keep using switch!

with 1 Comments