Alex Rivera | Logout

How to decorate a class as untestable for Code Coverage?

Asked 2009-10-21T19:00:15.873
25

Background: Visual Studio 2008, C#, .Net 3.5.

I have a number of utility classes that are simply not unit-testable. This is mainly because they interact with resources (e.g. databases, files etc).

Is there a way I can decorate these classes so that the Visual Studio Code Coverage engine will ignore them, so not decreasing the code coverage percentage?

Edit
Report

1 Answer

24

There is an answer in this article about how to use [System.Diagnostics.DebuggerHidden] or [System.Diagnostics.DebuggerNonUserCode] Attributes to exclude methods from code coverage.

Update as per David's comment:

As of .NET 4.0 there is a dedicated attribute for this: [ExcludeFromCodeCoverage]

answered 2009-10-21T19:53:33.800

Your Answer