2

This question is the modern reincarnation of Exclude auto properties from Code Coverage in Visual Studio 2015 I am only interested in VS 2019 and .Net Core 3.1.

My current CodeCoverage.runsettings file contains the following section:

<Attributes>
  <Exclude>
    <Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
    <Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
    <Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
    <Attribute>^System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute$</Attribute>
    <Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
  </Exclude>
</Attributes>

The point is that the auto properties are attributed with CompilerGenerated attribute. However, this approach is wrong, because the async methods are also transformed by the compiler into methods with this same attribute. So using this approach we lose coverage on the async methods. Not good.

So, is there a way in VS code coverage to skip coverage on auto properties like we can do in OpenCover or DotCover?

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

2

The following addition to my .runsettings file excluded auto props, but not manually coded properties or the async methods.

Under <CodeCoverage><Functions><Exclude>

     <Function>.*get_.*</Function>
     <Function>.*set_.*</Function>

Not perfect, but...

Peter
  • 971
  • 11
  • 12