Reputation: 1168
I am using Visual Stdio 2010 and its testing and code coverage features, and I have a bunch of generated code that I don't want to be included in code coverage results. These are generated as partial classes.
I've read in a few places (example: How to ignore generated code from code coverage data) how I can have the code coverage tools ignore the entire class or specific members using attributes. So I've modified the generator to include the [ExcludeFromCodeCoverage]
attribute on all of the classes it generates, but that prevents the code I write in partials from being tracked for code coverage as well.
How can I set things up such that code I manually write in partials are included in the code coverage results, but the generated code is not? The only option I am seeing now is to dig into the generator (a long, ugly T4 template) and add the [ExcludeFromCodeCoverage]
attribute at the property/method level instead of at the class level. Is there another way? I haven't seen anything like [IncludeFromCodeCoverage]
that I could add to my handful of properties/methods hand-written in partials to include those while ignoring the rest of the auto-generated class.
Upvotes: 1
Views: 1630
Reputation: 8358
You are not alone in requesting this as this entry on ExcludeFromCodeCoverage and other How to ignore generated code from code coverage data shows.
The other way I have seen this done with some other (eg ncover, partcover) coverage tools is to post process the results ie if XML use an xslt transform the xml to remove the coverage data related to the generated partials and then generate the coverage report.
You may be able to apply this approach or something similar as it looks like you can get access to the coverage data in XML.
OpenCover has a file filter that allows you to exclude all methods in a file that matches the filters, created for just this scenario as the names of generated files tend to follow known patterns, it also allows more than one filter.
Upvotes: 1