Lower symbol coverage than branch coverage?

Lower symbol coverage than branch coverage?

Hello,

I'm testing NCover 3.2.2, and I've a hard time understanding something.

For the example below, NCover gives me a symbol coverage of 83% for a branch coverage of 100%.


public static bool IsDelegate(this TypeDefinition typeDefinition)
{
(7)  if(typeDefinition.BaseType == null)
     {
(0)    return false;
     }

(7)  switch(typeDefinition.BaseType.FullName)
     {
       case "System.Delegate":
       case "System.MulticastDelegate":
(4)      return true;
       default:
(3)      return false;
     }
}

How branch coverage can be equal to 100% if return false is never executed?


RE: Lower symbol coverage than branch coverage?

Excellent question. Let me first say that the coverage situation ends up looking better on this method if you run it in release mode rather than debug mode, so that's part of the solution to your question.

This is actually an aspect of our branch coverage that we plan to improve in the future. Looking at a disassembly of the code you presented, the first statement branches to after the if block if the items being compared aren't equal, but it doesn't branch if they are, so there's only one branch point. That branch point gets marked as visited when it gets jumped to, but there's no effect to the branch coverage if the if block does or does not get entered.

In the future we hope to improve branch coverage to be more like distinct path coverage, so that it makes clear the percentage of all unique paths in a method that could be traveled that have actually been travelled.