Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore generated code from code coverage data

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 mentions using DebuggerNonUserCode and DebuggerHidden attributes. I have tried this an it works as advertised. DebuggerNonUserCode is set at the class level, but with 50+ classes generated in each of the generated service reference code files, this is not an attractive option.

Does anyone have any alternative solutions?

like image 703
btlog Avatar asked Jul 26 '10 18:07

btlog


People also ask

How do you exclude code from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class.

Which classes are excluded from code coverage calculation?

Test classes (classes that are annotated with @isTest ) are excluded from the code coverage calculation. This exclusion applies to all test classes regardless of what they contain—test methods or utility methods used for testing.


1 Answers

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.

like image 192
Paul Avatar answered Oct 06 '22 01:10

Paul