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
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=*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With