CoverageExclude
Eric Sink recently wrote an article, advocating the use of code coverage. In the article Eric writes about a hobby project of his where he has managed to achieve 100% code coverage. The following may be of interest to anyone who finds themselves driven towards such ridiculous levels of coverage. ;)
When using NCover, particular methods and classes can be marked with an attribute so they are excluded from the coverage report. TestDriven.NET tell NCover to use an attribute called 'CoverageExcludeAttribute' as this special attribute. When using the NCover console application, this option is:
//ea CoverageExcludeAttribute
The 'CoverageExclude' attribute isn't defined in an external assembly. This is because 'CoverageExclude' is most likely to be used in non-test code. We don't want to create a dependency on another assembly (just as you wouldn't want to reference 'nunit.framework' from non-test code). Instead the 'ExcludeAttribute' can be defined in the empty namespace as follows:
class CoverageExcludeAttribute : System.Attribute { }
Once defined this attribute can be used to exclude specific methods and classes from the NCoverExplorer coverage report.