Wednesday, June 13, 2007 9:16 AM
Don't get me wrong, code coverage is important...to an extent. But sometimes there are just those class that you just don't care if they're covered or not. Specifically, I'm thinking of the *.Designer.cs files that show up to hold the layout of your form controls or that contain the resources of your *.resx files. These classes often don't have adequate coverage but, normally, as they're automatically generated I'm not too concerned about it. However, I
would like for
NCoverExplorer to stop reminding me of it and recently I found a simple solution.
I'm sure that most of you are familiar with the
NCover exclude coverage attribute, if not you can find more information about it
here. Although this does work, it's always felt clunky to me. First of all, I don't like defining attributes by name versus type and secondly I've never been crazy about altering my code for the benefit of the tool. This is the same reason that I prefer to exclude FxCop rules in the project file rather than excluding them by code. There are also some other alternatives such as removing the PDB files for assemblies which you don't want covered, but that also feels clunky and only works at the assembly level. Luckily, there's a better way.
NCoverExplorer, much to my surprise, allows you to exclude reporting the coverage of certain objects based on naming conventions. You can find this little gem in NCoverExplorer under View->Options... and then on the Exclusions tab.
You can set this exclusion at the assembly, class, or namespace level. You can even use regular expressions! Once you've set your exclusions the objects which you've excluded will now show up under the Excluded branch of the coverage tree.
As you can see in this example, I've excluded my actual test assemblies from coverage analysis since I'm only interested the classes under test, not the tests themselves. Note that I could do this in the setup if launch NCoverExplorer directly, but as I usually run my coverage analysis from inside of
TestDriven.NET the setup is typically bypassed for me.
Remember, this doesn't prevent the objects from having coverage analysis...only from NCoverExplorer reporting that analysis to you. If you're interested in excluding certain objects from any analysis at all you can find plenty of MSBuild and NAnt tasks to do that for you.