question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage does not distinguish between property getters and setters

See original GitHub issue

Coverlet doesn’t appear to differentiate between property getter and setters when calculating coverage.

For example, given a project with only this simple class:

class MyClass
{
    private bool mandatory;
    public bool Mandatory { get => mandatory; set => throw new NotImplementedException(); }
}

And the test project only has the following test:

[Fact]
public void CheckMandatoryDefault()
{
    var sut = new MyClass();

    Assert.False(sut.Mandatory);
}

The test passes, the property is read via it’s getter, the setter is not called (i.e. the exception is not thrown) yet the coverage report says 100% coverage. I expected that the coverage report to show 50% coverage.

For completeness I tried changing the Mandatory property to use the following rather than expression bodies for the getter/setters in case the compiler was emitting some compiler generated attribute for expression bodies but it made no difference:

public bool Mandatory { get { return mandatory; } set { throw new NotImplementedException(); } }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
SteveGilhamcommented, Aug 1, 2019

@MarcoRossignoli The original NCover 1.x recorded start/end line/colum in its XML report, and for viewing classic NCover reports, the NCoverExplorer tool would show this level of detail 2019-08-01 and its coverage percentages are of the sequence points rather than lines (as is the summary emitted by OpenCover – which followed NCover in emitting sequence point start/end line/column information in the XML – at the end of its run).

1reaction
jeffanderscommented, Aug 1, 2019

@MarcoRossignoli There definitely seems to be some overlap (no pun intended) with this issue and #369 and your work on it. It looks like your work already improves the situation for lambdas at the very least (and presumably anonymous delegates). I have subscribed to that other issue and once it is complete/merged I will see if I have time/inclination at that point to circle back to this issue, see how it is affected by your changes and what remains outstanding and whether considering each of the aforementioned items as new branches under a separate command line switch is justified.

Thanks for the discussion thus far, it has been very interesting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coverage does not distinguish between property getters ...
Coverlet doesn't appear to differentiate between property getter and setters when calculating coverage. For example, given a project with ...
Read more >
Should unit tests be written for getter and setters?
If you write tests for getters and setters, you get a false sense of coverage and will not be able to determine if...
Read more >
Avoid getters and setters whenever possible
Getters and setters are a fake insurance policy of isolated change ... Public properties are not the same as getters and setters.
Read more >
Test Coverage for ENUM, Properties - Differences with ...
In the other class it counts as 1 of 2 lines covered. The first property is not counted nor covered. The one with...
Read more >
Is it a bad idea to use getters/setters and/or properties at all?
A user is arguing there against the use of getters/setters and properties. He maintains that most times using them is a sign of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found