What .Net coverage tools support "condition coverage"? [closed]
Asked Answered
G

3

5

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?

Galata answered 10/4, 2014 at 18:12 Comment(2)
I'm not really sure what I could do to make this comment more productive or researched. I've reviewed the products' forums, searched this site, as well as other sites, but have yet to come across any sort of concise answer. Any help would be appreciated.Galata
Ok, I tried to reframe the question as more fact-oriented. I'm not really interested in people's opinions about which coverage tools are better/worse. I'm interested in knowing which tools are capable of which types of coverage criteria or how to get the tools I mention to do what I need.Galata
S
0

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.

Sulfide answered 10/4, 2014 at 19:28 Comment(4)
I suppose I frame it in my mind not so much in terms of the execution of a hypothetical else statement, but in terms of code-paths. There are two discrete paths through this code. Either the statement being tested evaluates to true and the block is executed, or the statement evaluates false, and the block is not executed. It seems to me that there should be a distinction between covering the statements within the if block, vs covering the condition of the if block itself. No tools make this distinction?Galata
I completely understand your point, but I don't think any tool does this. Rather, they all rely on instrumenting (in one way or another) the code that is actually there and report whether or not it was executed.Sulfide
That's an unfortunate, but understandable limitation. Thanks for the reply!Galata
AxoCover (via OpenCover) does exactly that - puts two circles next to every if branch and colors them in one for true condition and one for false condition. It puts more circles if you throw in nullables and null-coalescing operators. But sadly not active anymore in 2022.Hecto
I
7

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

enter image description here

Insectarium answered 10/2, 2018 at 3:27 Comment(1)
Also AxoCover, which uses OpenCover under the hood, and displays markers directly in the code. Sadly OpenCover and AxoCover both seem to be dead - I'm trying NCrunch and dotCover and neither have branch coverage and frankly the free AxoCover was better than any of the paid products. AxoCover would show little circles for every single branch in a statement (if/switch/ternary/null coalesce etc) and color them in if each branch was tested. It would even give extra circles for things like nullables so it really made me work hard to test every possibility.Hecto
D
1

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.

Dispassionate answered 24/5, 2017 at 22:39 Comment(0)
S
0

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.

Sulfide answered 10/4, 2014 at 19:28 Comment(4)
I suppose I frame it in my mind not so much in terms of the execution of a hypothetical else statement, but in terms of code-paths. There are two discrete paths through this code. Either the statement being tested evaluates to true and the block is executed, or the statement evaluates false, and the block is not executed. It seems to me that there should be a distinction between covering the statements within the if block, vs covering the condition of the if block itself. No tools make this distinction?Galata
I completely understand your point, but I don't think any tool does this. Rather, they all rely on instrumenting (in one way or another) the code that is actually there and report whether or not it was executed.Sulfide
That's an unfortunate, but understandable limitation. Thanks for the reply!Galata
AxoCover (via OpenCover) does exactly that - puts two circles next to every if branch and colors them in one for true condition and one for false condition. It puts more circles if you throw in nullables and null-coalescing operators. But sadly not active anymore in 2022.Hecto

© 2022 - 2024 — McMap. All rights reserved.