I have a .NET 6 Core C# application with XUnit-based unit tests and "XPlat Code Coverage"/Cobertura/Coverlet test coverage analysis. One method in an EF data context class that was flagged as missing some branch coverage is really only a hook for use by the testing framework itself so I marked it with the ExcludeFromCodeCoverage attribute.
It's still being reported as deficient in branch coverage. The coverage report itself mocks me by displaying
[ExcludeFromCodeCoverage]
private void AdjustForTests(ModelBuilder builder)
{
...
while continuing to flag the branches as lacking in complete coverage. (AdjustForTests is called by OnModelCreating.)
This looks like it should be straightforward. ExcludeFromCodeCoverage always works for me when I apply it to a class. What might I be overlooking?
Evidently it just doesn't work at the method level. The documentation says it applies to classes and structs. I had thought I'd read otherwise a long time ago, and the compiler doesn't flag an error, unfortunately.