How to ignore generated code from code coverage data

后端 未结 4 1414
说谎
说谎 2020-12-16 13:00

I am using Visual Studio 2010 and would like to exclude the generated service reference code from my code coverage statistics.

I found an article pre 2010 that ment

相关标签:
4条回答
  • 2020-12-16 13:22

    System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage can be used on top of the class. This is a poor option since you need to redo this anytime you regenerate your code. Maybe Microsoft could do this for us automagically when creating service references, entity framework types, etc...

    0 讨论(0)
  • 2020-12-16 13:23

    The generated classes are partial. If you create a new class in your project with the same namespace and class declaration you can add the [ExcludeFromCodeCoverage] attribute to your partial class. That way you don't have to go back and edit the Reference.cs file whenever you refresh your reference.

    0 讨论(0)
  • 2020-12-16 13:36

    You could create a code generator that emits partial classes with the DebuggerNonUserCode attribute.

    0 讨论(0)
  • 2020-12-16 13:45

    In Reference.cs, you can find an existing attribute, like [System.Diagnostics.DebuggerStepThroughAttribute()] and do a search and replace with [System.Diagnostics.DebuggerStepThroughAttribute()][System.Diagnostics.DebuggerNonUserCode()].
    The major drawback is that you have to redo this each time you update the reference.

    I don't understand why MS does not make the code coverage tool smart enough to skip service reference generated code.

    0 讨论(0)
提交回复
热议问题