Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExcludeFromCodeCoverage attribute with dotCover in TeamCity 7

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

like image 248
adam197 Avatar asked Oct 25 '13 20:10

adam197


1 Answers

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=*

like image 190
kravasb Avatar answered Sep 22 '22 19:09

kravasb