I'm trying to more accurately reflect code coverage in a project I am working on but have run into a problem when it comes to Entity Framework generated classes. I'd like to exclude the constructors of these classes from coverage stats so I have added the ExcludeFromCodeCoverage
attribute to the T4 template which regenerates the classes as I would expect e.g.
using System.Diagnostics.CodeAnalysis;
public partial class Address
{
[ExcludeFromCodeCoverage]
public Address()
{
this.Person = new HashSet<Person>();
}
...
}
I'm attempting to add this at method level as there are some partial classes containing custom logic that needs to be tested and included in code coverage stats.
From what I have read the ExcludeFromCodeCoverage
should be automatically excluded when using dotCover but I'm not sure if this was true when running via TeamCity, so I included the filter as mentioned in Attribute filter syntax for code coverage in TeamCity (trying both ExcludeFromCodeCoverage
and ExcludeFromCodeCoverageAttribute
) with no luck.
Thanks
DotCover.exe
command line, in order to exclude code marked with theExcludeFromCodeCoverage
attribute you should use the followingdotCover.exe analyse ... /AttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
, you do not need the-:
syntax as with the/Filters=
parameter. – Transmittal