开发者

Is it possible to exclude Entity Framework Autogenerated Code from Code Coverage Statistics?

I have see开发者_JS百科n the [DebuggerNonUserCode] and [ExcludeFromCodeCoverage] attributes in resources and other SO questions about exlcuding code from coverage statistics, and wanted to know if it was possible to automatically add this attribute to the classes in the code generated by the Entity Framework using .NET 4.0.

Also would it need to be class level or could it be on the diagram.Designer.cs level, needing one attribute for all code generated by that diagram?


Since partial classes (which Entity Framework creates) merge attributes, extended functionality in other partial classes are also excluded if the attribute is class level in the template, it will have to be applied at the method level.

The best way that I've found to do this is using T4 (as recommended in @Craig Stuntz's answer) to:

  • include: using System.Diagnostics.CodeAnalysis; at the top of the file

Then apply [ExcludeFromCodeCoverage] to getters, setters and Factory methods by searching for:

  • #>get
  • #>set
  • Template_FactoryMethodComment

and placing them in the appropriate place.

This was made a lot easier using Tangible's T4 editor Extension for VS.

This is my first attempt and it seems to work, "your milage may vary", so complete a test run to make sure everything's working as necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜