Exclude Program.cs/top-level program from coverage
See original GitHub issueDescription
I have the top-level ASP.NET Core program src/WebApp/Program.cs using minimal APIs (see here). When calculating the coverage using dotnet-coverage collect 'dotnet test --no-build' -s 'src/Tests/dotnet-coverage-settings.xml' -f xml -o 'coverage.xml' (see here), this code is not excluded from coverage, although I’ve configured it in src/Tests/dotnet-coverage-settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<CodeCoverage>
<Attributes>
<Exclude>
<!-- Don't forget "Attribute" at the end of the name -->
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
<Sources>
<Exclude>
<Source>src/WebApp/Program.cs</Source>
</Exclude>
</Sources>
</CodeCoverage>
</Configuration>
In Coverlet I could resolve this with the following hack (see here):
[ExcludeFromCodeCoverage]
public partial class Program
{
}
But this doesn’t seem to work with dotnet-coverage.
Environment
- .NET SDK →
7.0.100 dotnet-coverage→17.5.0- Running as GitHub Action (see here)
Issue Analytics
- State:
- Created 9 months ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Excluding Program.cs from code coverage in .net 6
To exclude my code from code coverage in a .net core webapi project, I apply the [System.Diagnostics.Analysis.ExcludeFromCodeCoverage] attribute ...
Read more >Untitled
Exclude program.cs from code coverage Configuring a Project to Exclude Certain ... zeros of a polynomial Exclude Program.cs/top-level program from coverage ...
Read more >How to exclude code from code coverage
The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class ...
Read more >Customizing Code Coverage Analysis - Visual Studio
Learn how to use the ExcludeFromCodeCoverageAttribute attribute to exclude test code from coverage results. You can include assemblies ...
Read more >Exclude Nodes from Coverage Snapshot - dotCover
When a coverage snapshot is created, you can exclude specific items from its current presentation. As soon as you do this, dotCover will ......
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 Free
Top 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
Okay, thx for your help! I’ll ping Sonar again (see here) and close this issue in the meantime.
It looks good in report. Methods are excluded:
Could you please upload during run and provide coverage report from github actions?