Daily Usage Issues

Coverage not detected

Started by kentcb on 4,515 views

Hi,

I'm running 3.3.0.6 in VS2015.

I have a SUT that NCrunch is reporting as not fully covered. 2 out of 5 properties on the SUT are shown as covered, the other 3 uncovered. But I do have tests covering all properties and have verified those tests are running (and reset the execution engine to be sure).

Here's an example of a test that is _not_ detecting as covering the PhotoUri property:


        [Theory]
        [InlineData(null)]
        [InlineData("")]
        [InlineData("foo")]
        [InlineData("bar")]
        public void photo_uri_reflects_campus(string photoUri)
        {
            var campus = new CampusMockBuilder()
                .WithPhotoUri(photoUri)
                .Build();
            var sut = new CampusViewModelBuilder()
                .WithCampus(campus)
                .Build();

            Assert.Equal(photoUri, sut.PhotoUri);
        }


But if I add this test the PhotoUri property _is_ detected as covered (but only by a single test):


        [Fact]
        public void foo()
        {
            var sut = new CampusViewModelBuilder()
                .Build();

            Assert.Null(sut.PhotoUri);
        }


On a hunch, I tried changing it to a theory (suspicious that theories weren't contributing to coverage statistics):


        [Theory]
        [InlineData(1)]
        public void foo(int whatever)
        {
            var sut = new CampusViewModelBuilder()
                .Build();

            Assert.Null(sut.PhotoUri);
        }


But this _still_ reported PhotoUri as covered (again, by this single test).

I then removed the foo test and tried commenting out [InlineData("")] in the original test, letting tests run, then uncommenting it. Sure enough, this time the engine picked it up and shows it as covered.

What would cause this?

Thanks

PS. gods bbcode is super painful

Edited

Hi, thanks for sharing this problem.

I've tried to construct a small reconstruction of this, but it's hard to understand how the pieces here connect without the actual code behind this.

A few things worth checking:

- Try running the test with a debugger to see which lines it actually hits. NCrunch records its coverage through which lines are physically touched by .NET while it executes as defined in the PDB, so this is a good way to check whether your code is behaving the way you expect it to.
- Try examining the code coverage for ONLY those tests that you would expect to touch the properties (i.e. right click on them and choose the show coverage only option). Examine the physical trace path of the test. Does this match your expectation of the code?

If you think this is a problem with NCrunch misreporting something, you are most welcome to build a reproduceable code sample that compiles independently and submit it through https://www.ncrunch.net/support/contact and I'll examine it in more detail.

Edited

Post a reply

Log in to reply.