views:

387

answers:

4

I'm running VS2008's Code Coverage against a unit-tested DLL that I'm developing. For some of the functions it claims that 2 blocks are not covered and 50 or so are. When I view the function with the VS2008 highlighting it can't find the uncovered blocks.

The highlighting appears to work with some functions though as it correctly shows a different color for uncovered blocks. Seems to be inconsistent.

Is this a bug or PIBKAC? If the latter, what am I doing wrong?

+1  A: 

Just a suggestion, try the code coverage tool from TestDriven.Net and compare the results.

Kasper
+1  A: 

I've seen some issues where the code coverage analyzer has trouble with closing braces on try/catch blocks. When I see these sorts of things, I just don't worry about it -- as long as I can see that the actual code gets covered.

[EDIT] I'd second the TestDriven.NET recommendation. I like it for the right-click test menus that let me easily run individual tests and I also use NCover rather than the built-in coverage -- mostly because it opens in another window and doesn't color the text in my main editor.

tvanfosson
It's easy to run individual tests in VS: instead of Run All Tests In Solutions (Ctrl+R/A and Ctrl+R/Ctrl+A) you have Run Tests In Context (Ctrl+R/T and Ctrl+R/Ctrl+T) which runs tests based on where the cursor is. In TestClass runs class, in TestMethod runs just that method.
peSHIr
I came across your response when searching for the closing brace issue. I had a red highlight on a closing brace and I discovered that it actually was a lack of coverage, not a bug. My code was in a try/catch, and the test was actually throwing an exception every time, which was being caught, but my tests never actually got to the end of that block because it always escaped into the try/catch. So by making a test not throw an exception and get to the end of the block, the coverage was 100%. Hope this helps.
Paul
+1  A: 

Make sure to differentiate between covered blocks and partly covered blocks. The color is similar in the default settings, if i recall correctly.

mafutrct
A: 

I had a situation in which a switch statement that chose a different path for every member of an enumeration didn't have a "default" path. You could spot the not-completely-covered block by the parens of the switch statement not being highlighted.

Dave Van den Eynde