ExcludeFromCodeCoverage not working for autogen getters and setters
See original GitHub issueNoticed that when trying to apply the excludeFromCoverage attribute to getters and setters from a class property, they are not taken into account
public class Key
{
[ExcludeFromCodeCoverage]
public int Id { get; set; }
public Guid Uuid { get; set; }
public Guid Kid { get; set; }
}
"/build/src/Keys.Data/Entities/Key.cs": {
"Keys.Data.Entities.Key": {
"System.Int32 Keys.Data.Entities.Key::get_Id()": {
"Lines": {
"10": 0
},
This can easily be seen in action in existing tests within coverlet. In InstrumenterTests.cs
, in the TestInstrument_ClassesWithExcludeAttributeAreExcluded
Just remove the [ExcludeFromCodeCoverage] attribute from one of the classes that this method uses in Samples.cs
and add a property like this Id
one.
For example in Samples.cs
change this class as follows:
public class ClassExcludedByCoverletCodeCoverageAttr
{
public string Method(string input)
{
if(string.IsNullOrEmpty(input))
throw new ArgumentException("Cannot be empty", nameof(input));
return input;
}
[ExcludeFromCodeCoverage]
public int Id { get; set; }
}
Then you will that in method InstrumentType
from Instrumenter.cs
the attributes don’t show up, because the method name is changed to get_Id()
(autogenerated) and so it gets instrumented anyway.
Can we fix this somehow?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14 (8 by maintainers)
Top Results From Across the Web
ExcludeFromCodeCoverage not working for autogen ...
Noticed that when trying to apply the excludeFromCoverage attribute to getters and setters from a class property, they are not taken into ...
Read more >c# - Exclude auto properties from Code Coverage in Visual ...
The problem is that you have properties on a class that are not touched by any unit test code. They are unused code....
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
Now we can use
p:ExcludeByAttribute=\"CompilerGeneratedAttribute\"
to skip autogen propOk reopening for further investigation