Option to ignore field/property initializers and auto-implemented properties
See original GitHub issueConsider a class, e.g.
class MyClass
{
public int MyValue { get; set; }
}
The property would be excluded because it’s getter/setter has the CompilerGeneratedAttribute set. Now consider this class:
class MyClass
{
public int MyValue { get; set; } = 42;
}
The line is included in coverage. I think this is because in the IL code, the initializers are actually part of the constructor. While this may be a sensible default even if explicitly opting out of compiler generated code, there should be an option to exclude initializers from coverage analysis.
The use case for this is when you have large model objects that contain code that you actually want coverage on, but also contains lots of pure data members.
Suggestion is to include an option, e.g. ExcludeInitializers
, that ignores all initializers from coverage.
I saw e.g. issue #316, but I would argue something more specific than an arbitrary “IgnoreTrivial” is more suitable.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (1 by maintainers)
Top GitHub Comments
Just passing by - I was able to use this today effectively, as the overall coverage % wasn’t valuable to me while I was unable to skip such trivial code. I was searching for such a feature all of Friday, and just saw it in the documentation today.
So thank you, this was wonderful timing.
@rickardp - If its reporting a class member that is unused or untouched by any of the unit tests it should be reported as not covered. Is this what you mean?