coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

Addind a private const in a static class causes Coverlet to completly ignore assembly

Open RobertoBiundo opened this issue 2 years ago • 5 comments

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.

  1. Create a Project, run tests for a simple class on that project (ensure that tests coverage is in the output files)
  2. 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; }
  3. 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

RobertoBiundo avatar Jan 25 '23 14:01 RobertoBiundo

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?

MarcoRossignoli avatar Jan 26 '23 15:01 MarcoRossignoli

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.

daveMueller avatar Jan 26 '23 22:01 daveMueller

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Sep 03 '23 01:09 github-actions[bot]

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.

Issue1438.zip

daveMueller avatar Feb 29 '24 16:02 daveMueller

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Jun 02 '24 01:06 github-actions[bot]