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.

Option to ignore field/property initializers and auto-implemented properties

See original GitHub issue

Consider 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:closed
  • Created 5 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
svengeancecommented, Aug 4, 2020

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.

0reactions
StingyJackcommented, Apr 11, 2021

Consider 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:

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Option to ignore field/property initializers and auto ...
Suggestion is to include an option, e.g. ExcludeInitializers , that ignores all initializers from coverage. I saw e.g. issue #316, but I would ......
Read more >
Why can only auto-implemented properties can have ...
I get the "only auto-implemented properties can have initializers in C#" error when trying to do the following:
Read more >
Automatic properties in C#
Since C# 6.0 we can use automatic property initializers so we can directly assign initial value to automatic property. public class Dummy {...
Read more >
Auto-Implemented Properties - C# Programming Guide
Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors.
Read more >
Index of EditorConfig properties | ReSharper Documentation
This page lists custom ReSharper EditorConfig properties that you can use ... Align multiline construct - Initializer list arguments (C++).
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