Question

I am just starting with code coverage tools (primarily in C#). So far I have tested out NCrunch and DotCover.

They both seem to do a good job with branch and function coverage, but I can't tell for sure if they're doing conditional coverage. For example, in some code I'm testing, the following shows as covered so long as there is at least one path through (or am I wrong about that?). However, it seems to me that it should only be covered if both logical paths through the code are covered.

if (item != "")
{
    glc.AddGrayListItem(GrayListTypeEnum.BlackList, item);
}

What I'd like to know is if DotCover or NCrunch (or any other tool for C#) will tell me that this isn't covered unless both cases (item != null) and (item == null) are tested.

I've looked on various sites and can't seem to find a definitive answer about whether either of these tools works this way, or if there's another tool that does work this way. Do any of you have definitive information about what types of coverage various code-coverage tools do or do not supply?

Was it helpful?

Solution 3

Personally, I know of no coverage analysis tool that would tell you whether or not a hypothetical (absent) else part of an if statement would have been executed.

OTHER TIPS

The current version of OpenCover will does cover this in branch coverage metrics:

enter image description here

In case others are interested in an answer to this question... NCover is the only tool I have found that does the job so far (2017). I have checked Visual Studio Enterprise Code Coverage, NCrunch, Resharper dotCover, OpenCover and NDepend. None of them supported the Condition Coverage case you asked for. NCover shows a 66.67% condition coverage if the unit test doesn't cover both true and false cases in your example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top