ExcludeFromCodeCoverage attribute with dotCover in TeamCity 7
Asked Answered
P

1

9

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

Psalms answered 25/10, 2013 at 20:57 Comment(0)
S
17

I have the same TeamCity version as yours. It works fine for me. You should check if your configuration is correct.

You should specify attribute name in the Attribute Filters: section. In your case the text should be :

-:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute

Marked members should not be displayed (for classes) or marked green/red in you your TeamCity coverage report.

More instructions can be found here

I had the similar issue. I excluded generated class from coverage by adding to my "Code coverage" build step:

-:assembly=<assembly name>*;type=*<part of generated classname>*;method=*

Savil answered 29/10, 2013 at 12:56 Comment(1)
This comment isn't directly related to TeamCity & DotCover, but for those using the DotCover.exe command line, in order to exclude code marked with the ExcludeFromCodeCoverage attribute you should use the following dotCover.exe analyse ... /AttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute, you do not need the -: syntax as with the /Filters= parameter.Transmittal

© 2022 - 2024 — McMap. All rights reserved.