Excluding code from NCover

|
One of the most frustrating things about Web References, Resource Files and their brethren is that they result in NCover (by default) showing a stupidly low Code Coverage %. There's an easy way around this, particularly if you're using TestDriven.net

Create an attribute called CoverageExcludeAttribute:

using
System;

[AttributeUsage(AttributeTargets.All)]
public class CoverageExcludeAttribute: Attribute {}
A good place to put it is in a shared assembly, or in your AssemblyInfo.cs if your class/project is somewhat monolithic. Now, every class or method that you decorate with this attribute will be ignored by NCover (when run via TestDriven.net). You can also make any nant build tasks you have running in CruiseControl do the same:

<ncover program="NCover.Console.exe" commandLineExe="nunit-console.exe" commandLineArgs="My.Test.dll /xml=Coverage.xml /labels /nologo" coverageFile="Coverage.xml" logLevel="Verbose"
logFile="My.log"
excludeAttributes="CoverageExcludeAttribute;System.CodeDom.Compiler.GeneratedCodeAttribute" registerProfiler="false">
</ncover>

Note the second attribute that's in there - "System.CodeDom.Compiler.GeneratedCodeAttribute", that's the one that automatically excludes any code that Visual Studio / other MS tools automatically generates, leaving the "CoverageExcludeAttribute" for when you need to (judiciously!!) apply it.

About this Entry

This page contains a single entry by Robert Wray published on January 23, 2009 12:19 PM.

AWOL Immediate Window in Visual Studio was the previous entry in this blog.

The Playmobil Security Checkpoint - Sheer Genius is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.04