Skip to content

Can't use [ExcludeFromCodeCoverage] on a static method? #1484

Closed
@romainf-ubi

Description

@romainf-ubi

I have this C# code:

internal static class PolicyNames
{
    public const string Read = nameof(Read);
    public const string Write = nameof(Write);

    [ExcludeFromCodeCoverage]
    public static IEnumerable<string> All()
    {
        yield return Read;
        yield return Write;
    }
}

I use the NuGet package coverlet.collector 3.2.0, and I use dotnet test -c Release --collect="XPlat Code Coverage" to generate the coverage reports.

Apparently my method All() is still covered. If I move [ExcludeFromCodeCoverage] over to the static class, then All() is excluded (but also is the whole class).

Note: I opened this issue after writing this comment on another closed issue.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwith reproIssue with repro

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions