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.

ExcludeFromCodeCoverage not working for autogen getters and setters

See original GitHub issue

Noticed 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoRossignolicommented, Oct 14, 2019

Now we can use p:ExcludeByAttribute=\"CompilerGeneratedAttribute\" to skip autogen prop

0reactions
MarcoRossignolicommented, Mar 6, 2021

Ok reopening for further investigation

Read more comments on GitHub >

github_iconTop 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 >

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