How do I exclude types and methods from being covered by dotCover in TeamCity?

Martin R-L picture Martin R-L · Apr 12, 2011 · Viewed 14.2k times · Source

I've got an existing C# 4 project which I've checked the test coverage for by using TestDriven.Net and the Visual Studio coverage feature, i.e. Test With -> Coverage from the context menu.

The project contains some code I don't want covered, and I've solved that by adding the [ExcludeFromCodeCoverage] for those types and methods.

We've just upgraded TeamCity to 6.0.3, and I've added dotCover coverage to the NUnit build step.

I've managed to remove coverage for external assemblies such as NHibernate in the "Filters" section (by explicitly state the assemblies for which I want coverage), but I'm struggling with how to exclude types and methods from covered assemblies.

enter image description here

Answer

Anthony Mastrean picture Anthony Mastrean · Jun 2, 2011

Ok, Martin, I figured it out! It only took an hour of randomly poking at the filter syntax... when the documentation says to add a filter like this

+:myassembly=*;type=*;method=***

They really mean this... where anything in <> is replaced entirely by you and anything else is a literal

+:<myassembly>;type=<filter>;method=<filter>

So, the filter I wanted was to include a single assembly (from a bunch of assemblies) and then exclude a few namespaces in that assembly. I wrote

+:Omnyx.Scanner
-:Omnyx.Scanner;type=Omnyx.Scanner.Simulation.*
-:Omnyx.Scanner;type=Omnyx.Scanner.ToolsCommon.*