Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding Program.cs from code coverage in .net 6 [duplicate]

To exclude my code from code coverage in a .net core webapi project, I apply the [System.Diagnostics.Analysis.ExcludeFromCodeCoverage] attribute to the unwanted classes.

Now I would like to exclude Program.cs from my code coverage. However, in .net 6 I don't know how to apply an attribute to this file because it does not have a class declaration. Can anyone guide me on how I can apply an attribute to this file?

like image 457
Wayne Allen Avatar asked Dec 18 '25 16:12

Wayne Allen


1 Answers

I don't think you can use attributes, but you can exclude the program.cs in the dotnet test command - like this.

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:ExcludeByFile="**/program.cs"

like image 127
Anuraj Avatar answered Dec 21 '25 07:12

Anuraj