Addind a private const in a static class causes Coverlet to completly ignore assembly
I have a project where I create some static classes to server as extensions for things like app startup configuration (builders)
If a line gets added to one of those static classes defining a private constant and coverlet is called from the command line the resuilting XML/JSON will not contain the code coverage for the entire project (this is a multi project solution, other projects do still show).
Steps to reproduce.
- Create a Project, run tests for a simple class on that project (ensure that tests coverage is in the output files)
- Create a static class in the project that constains a private const (does not need to referenced from anywhere)
public static class SameSiteCookiesServiceExtensions { private const SameSiteMode Unspecified = SameSiteMode.Unspecified; } - Re run the test coverage
dotnet test --configuration Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings
Expected:
- The project that contains the public static class should still show up in the coverage.cobertura.xml and coverage.json outputs
Actual result:
- The project no longer shows in the output xml or json
I have managed to bypass the issue for now by replacing the
private const SameSiteMode Unspecified = SameSiteMode.Unspecified;
with
private static readonly SameSiteMode Unspecified = SameSiteMode.Unspecified;
but this is not ideal
const are "moved" at build time by the compiler for performance reason I don't know if we can do a lot for this issue, @daveMueller do you know if we have other issue like this one?
No sorry, first time I hear about an issue like this. Even if the const is moved I think it is still a bit weird that coverlet excludes the whole project. I guess we should debug this to actually see why the assembly is excluded. Btw, @RobertoBiundo thanks for the repro.
This issue is stale because it has been open for 3 months with no activity.
I tried to reproduce this today but wasn't successful. The project with private const SameSiteMode Unspecified is part of the coverage report. I used the attached solution. I would need a repro for this issue to do further analysis.
This issue is stale because it has been open for 3 months with no activity.