Daily Usage Issues

Code coverage incorrect

Started by openshac on 4,767 views

The following code snippets give different code coverage stats:

if (isValid) return;


if (isValid)
{
return;
}


The first example has 100% coverage if isValid = false
The second example has <100% coverage if isValid = false

Now I appreciate some developers will say that all if statements should have braces, but we have a lot of legacy code that doesn't.

DotCover returns < 100% which is what I'd expect.
Hi, thanks for sharing this.

Although no doubt many people will be unhappy about me saying this, this problem is by design.

NCrunch's code coverage only has line-by-line resolution. NCrunch does not separate lines into statements for more detailed analysis.

The reasons for this are as follows:
- Performance
- Implementation difficulty (the coverage tracking/merging of NCrunch is very high performance and extremely complex)
- Aggregation/UI complexity (it's hard to meaningfully show partially covered lines with markers in a way that fits with the existing model)

Given the above constraints, it is unlikely that this design will be changed in the near future.

Post a reply

Log in to reply.