Hi,
NCrunch does not give the same coverage metric for the following 2 classes,
although functionally they are identical.
Does Ncrunch coverage work on the code line as in the editor;
or on msil code itself, like ncover does ?
// Will be 100% coverage
public class CoverageWithoutNewLine
{
public bool Do(bool b)
{
if (b) return true;
return false;
}
}
// Will be 80% coverage
public class CoverageWithNewLine
{
public bool Do(bool b)
{
if (b)
return true; // not covered
return false;
}
}
The test code to reproduce:
using NUnit.Framework;
namespace NcrunchCoverage
{
[TestFixture]
public class CoverageTest
{
[Test]
public void WithNewlineTest()
{
CoverageWithNewLine c = new CoverageWithNewLine();
Assert.False(c.Do(false));
}
[Test]
public void NoNewLineTest()
{
CoverageWithoutNewLine c = new CoverageWithoutNewLine();
Assert.False(c.Do(false));
}
}
}
Yes, there is a difference between how the code coverage is calculated/considered between NCrunch and NCover.
While both work at MSIL level, NCrunch uses a lower resolution for coverage detection - working on a line-by-line basis, while NCover works by statement. The reason for this is actually visual - with NCrunch, at the moment there isn't a way to show the partial coverage of a line via the markers on the left margin. Instrumenting on a statement-by-statement basis would also greatly increase the weight of the instrumentation (thus further slowing down your runtime code).
it is important that NCrunch doesn't show that a line is coveraged, when not all statements of a line are coveraged by tests.
Additional information could be shown in the Tooltip of the marker.
+1 for this. I find myself going back to fixing unit tests after continuous integration server reports missing coverage on some statements where NCrunch reports 100%.
The NCrunch Metrics is a little misleading since it states "Code Coverage %" and not "Code Line Coverage %" which is the actual case.
If this slows NCrunch down I would at least want an option to enable it. I currently can't rely on NCrunch as a code covering tool but in addition to NCrunch must rely on 3rd party tool to do a more detailed code coverage.