Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Coverage Metric differs on coding style
ylorph
#1 Posted : Monday, May 21, 2012 11:07:47 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/21/2012(UTC)
Posts: 1

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 ?
Code:
// Will be 100% coverage
    public class CoverageWithoutNewLine
    {
        public bool Do(bool b)
        {
            if (b) return true;
            return false;
        }
    }

Code:
// 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:

Code:
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));
        }
    }
}
Remco
#2 Posted : Monday, May 21, 2012 8:35:54 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi -

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).

I hope this helps.


Cheers,

Remco
Ramius
#3 Posted : Friday, May 25, 2012 2:54:05 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/25/2012(UTC)
Posts: 2
Location: Germany

Was thanked: 3 time(s) in 1 post(s)
Hi,

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.

Regards,

Ramius
3 users thanked Ramius for this useful post.
Remco on 5/25/2012(UTC), zastrowm on 8/19/2012(UTC), GreenMoose on 10/31/2012(UTC)
GreenMoose
#4 Posted : Wednesday, October 31, 2012 11:17:34 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
+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.
2 users thanked GreenMoose for this useful post.
Remco on 10/31/2012(UTC), DanHil on 11/14/2012(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download