Build/Test Issues

Code coverage results are strange when using conditional

Started by strike2867 on 5,349 views

Using the following test code

public int TrySomething(int x)
{
int z = x > 5 ? 2 : 3;
return z;
}

[TestMethod]
public void TestTrySomething()
{
var actual = TrySomething(10);
Assert.AreEqual(2, actual);
}

VS code coverage shows it as 80% covered in VS 2012 but we get a green circle as that row being covered. I'd expect some kind of mixed circle instead of just showing as fully covered.
Hi -

Thanks for sharing this. Right now NCrunch's code coverage resolution works to the line only (not to the statement), so as you've described, there is granularity that is lost here in the coverage reporting.

This has been an often requested feature although at this stage I haven't yet found a way to implement it. The complexity of the NCrunch algorithm that maps code coverage is staggeringly complex, and getting it to perform acceptably with statement level coverage is a fairly epic challenge.

I appreciate you mentioning this though, as it does help to underscore the need.


Cheers,

Remco

Post a reply

Log in to reply.