Skip to content

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

Open
@RobertoBiundo

Description

@RobertoBiundo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproNeeds repro to be investigated, cannot repro in localstaletenet-coverageIssue related to possible incorrect coverage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions