How to decorate a class as untestable for Code Coverage?

Viewed 14070

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?

4 Answers

I imagine there is more than one class in your test project and so an option to consider would be to directly exclude the test project from coverage. You can achieve that by adding this code in your ClassTests.csproj :

<ItemGroup>
        <AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" />
</ItemGroup>
Related