Coverage does not distinguish between property getters and setters
See original GitHub issueCoverlet 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:
- Created 4 years ago
- Comments:17
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 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).
@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.