Excluding Program.cs from code coverage in .net 6

Viewed 3657

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?

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"

Related