Skip to content

Introduce a suppressor for CA1515 #12528

Closed
Closed

Description

Summary

In general, we enable the maximum of analyzer rules (even with "warning as error" enabled).
We currently have to explicitly disable CA1515 in our unit test projects as MSTest test classes have to be public.

When that analyzer rule is enabled, the following diagnostic is produced for test classes:

error CA1515: Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)

It would be great if MSTest shipped with a DiagnosticSuppressor that suppresses CA1515 for MSTest test classes.

Alternate solution would be to modify CA1515 itself to not report the diagnostic for MSTest test classes.

Activity

  1. added
    needs/triage
    on Nov 19, 2026
  2. added
    area/analyzers
    and removed
    needs/triage
    on Nov 19, 2026
  3. Evangelink commented on Nov 19, 2026

    @Evangelink
    Member

    Opened dotnet/sdk#57223 to ask whether CA1515 should recognize MSTest test classes. It also links the earlier cross-framework report, dotnet/roslyn-analyzers#7192, now in an archived repository.

    An MSTest-only exemption in the SDK would give it preferential treatment over other test frameworks, so the upstream issue asks for a consistent policy. We should still consider a targeted DiagnosticSuppressor in MSTest.Analyzers here, independently of that decision. This would avoid disabling CA1515 for unrelated public types and could help users on existing SDK/analyzer versions.

    Keeping this issue open for that suppressor proposal; it is not blocked on the SDK discussion.

  4. drieseng commented on Nov 19, 2026

    @drieseng
    Author

    Amaury Levé (@Evangelink), I think it would be better to implement this in MSTest as it does not appear to apply to NUnit (it allows for internal test classes) and xUnit ships with a suppressor of its own.

    Analysis of CA1515 for regular projects / assemblies should not slowdown due to an extra check that only applies to MSTest test classes.

  5. Evangelink commented on Nov 19, 2026

    @Evangelink
    Member

    Fixed by #12538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/analyzers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions