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:
<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.
Create an attribute called CoverageExcludeAttribute:
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:
using System;
[AttributeUsage(AttributeTargets.All)]
public class CoverageExcludeAttribute: Attribute {}
<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.
