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?
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With