Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decorate a class as untestable for Code Coverage?

Tags:

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?

like image 917
Chris Arnold Avatar asked Oct 21 '09 19:10

Chris Arnold


2 Answers

When you upgrade your project to .NET 4, you'll get the ExcludeFromCodeCoverageAttribute Class.

like image 51
brickner Avatar answered Sep 29 '22 10:09

brickner


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]

like image 27
John K Avatar answered Sep 29 '22 09:09

John K