Coverage exclusion does not seem to work :(
See original GitHub issueHi 😃
I cannot get coverage exclusion as described here to work. If I include the ExcludeByAttribute
property in my *.Tests.csproj
file and add a property GeneratedCode
to my generated code project then Coverlet still computes coverage for the generated code. Similarly if I add the property ExcludeFromCoverage
or ExcludeFromCodeCoverage
to my generated code project, coverage is again still computed for the project.
Here is my *.Tests.csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<CollectCoverage>true</CollectCoverage>
<CoverletOutputFormat>lcov</CoverletOutputFormat>
<CoverletOutput>./Datahub/lcov.info</CoverletOutput>
<ExcludeByAttribute>GeneratedCode</ExcludeByAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="FluentAssertions" Version="5.10.0" />
</ItemGroup>
<ItemGroup>
... project references ...
</ItemGroup>
</Project>
and here is my ProtoBuf.csproj
file for the generated code:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratedCode>GeneratedCode</GeneratedCode>
<ExcludeFromCoverage/>
<ExcludeFromCodeCoverage/>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
<PackageReference Include="Grpc" Version="2.26.0" />
<PackageReference Include="Grpc.Tools" Version="2.26.0" PrivateAssets="All">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="**/*.proto" />
</ItemGroup>
</Project>
Am I missing something or what is wrong?
Thanks 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top Results From Across the Web
Sonar.coverage.exclusions not excluding too much
When adjusting this field in the sonarqube-project.properties file, it looks like files get excluded in the code, but even ones that aren't ......
Read more >Coverage exclusion does not seem to work :( · Issue #722
Hi :) I cannot get coverage exclusion as described here to work. If I include the ExcludeByAttribute property in my *.
Read more >Sonar exclusions are not working which mentioned in ...
I'm using GitLab CI/CD pipeline for deploying the Springboot project. I have integrated SonarQube in my project. In my sonar-project.properties ...
Read more >Re: sonar.coverage.exclusions not working when added ...
I am using the version 2.5 of the gradle plugin and in the sonar scanner context, i can see the property, so it...
Read more >Do You Know Your Insurance Policy's Coverage Exclusions?
The CGL policy's “Your Work” exclusion means that there would be no insurance for such a claim (usually brought as a breach of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just want to give a small update to this that I just discovered. You do not have to create a C# file with the attribute above, the same thing can be done in the
csproj
file like this:I now added a file
coverage.cs
to my ProtoBuf project with the following content:and now that project is not included in the coverage 😃 Thanks for the help 😄
I think that it would clear up the documentation, if a more explicit explanation is added for how to ignore a class/module/assembly. I misunderstood C# attributes with MSBuild properties so I guess others could also do that 😃