I want to exclude all auto generated migration files from code coverage caculation. I can't change the dotnet test
command in the build pipeline so I guess my only friend is the [ExcludeFromCodeCoverage]
attribute.
The tricky part is that everytime I add a new migration, I need to manually review all generated files and ensure I have [ExcludeFromCodeCoverage]
attribtute on all generated classes, this is fine but I am wondering is there a better solution that I can do it once and for all?
The migration file
[ExcludeFromCodeCoverage] // Manually added everytime
partial class Initial : Migration
And the ModelSnapshot file
[ExcludeFromCodeCoverage] // This gets removed everytime snapshot is updated
[DbContext(typeof(MyContext))]
partial class MyContextModelSnapshot : ModelSnapshot
For the snapshot file, since the class name is always the same I can creat a sperate file MyContextModelSnapshot.CodeCoverage.cs
file and put the attribute on the partial class, but is there a solution for the Migration files?
I am working with coverlet.msbuild
if it matters.
dotnet test
command?dotnet test -s codecoverage.runsettings
? Orcodecoverage.runsettings
is a magic filename that will be picked by default? – Trave