Skip to content

ExcludeFromCodeCoverage not working for autogen getters and setters #269

@pape77

Description

@pape77

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtenet-coverageIssue related to possible incorrect coverage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions