ExcludeFromCodeCoverage attribute is ignored in an static class in a ASP.NET Core 3.1 project
See original GitHub issueHi all,
I’m facing an issue when using Coverlet in a ASP.NET Core 3.1 project. I can see that a static class, which has a static void method, is not being excluded from code coverage, although both the class and the method have the ExcludeFromCodeCoverage attribute applied, from the namespace System.Diagnostics.CodeAnalysis
.
This static method is an extension method referenced by the Startup class in my ASP.NET Core 3.1 project, Startup and Program classes are also excluded from code coverage and they don’t appear in the code coverage results, however my static class and its static void method appear in the results.
Is this a known issue with Coverlet, .NET Core 3.1 and static classes and methods? This is the command I’m running to get the results:
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
My unit test project references coverlet.msbuild with version 2.7.0. It also references Xunit, version 2.4.1, and my ASP.NET Core 3.1 project. The unit test project also targets .NET Core 3.1. This is extracted from my csproj file for the reference to coverlet.msbuild:
<PackageReference Include="coverlet.msbuild" Version="2.7.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
I found this issue in my build pipeline in Azure DevOps too.
Finally, I’d like to mention that the code coverage tools included in Visual Studio 2019 Enterprise, version 16.4.2, do exclude the class and the method from code coverage, so I think this is an issue with Coverlet itself, or the commands I’m using with dotnet test
.
Please advise.
Regards, Jorge
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top GitHub Comments
@jmoralesv I did a repro and the issue is “related” to the other, btw for now I’ll leave this open because I don’t know if the fix will work with “nested” async machine state.
For now you can remove that file from coverage using filters,
ExcludeByAttribute
exclude by attribute name andCompilerGeneratedAttribute
is the attribute added by the compiler to the state machinesOr you can use filter by filename
In my repro I put the extension inside a file called
Ext.cs
Sure thing!