Skip to content

CA1515: account for MSTest test classes that need to remain public #57223

Description

@Evangelink

Problem

Related: microsoft/testfx#12528.

When CA1515 (Consider making public types internal) is explicitly enabled, it flags public MSTest test classes in executable test projects. MSTest's default discovery requires these classes to be public, so following the diagnostic can prevent tests from being discovered. Users enabling all analyzer rules, especially with warnings treated as errors, currently need to suppress the diagnostic themselves.

MSTest does support opting into internal test discovery with [assembly: DiscoverInternals], but existing projects should not have to change their discovery configuration just to follow this diagnostic. This request is about CA1515 when enabled, not changing its default severity.

The current rule implementation filters by output kind and reports public named types without a test-class exception.

Request

Could CA1515 recognize MSTest test classes and avoid recommending an accessibility change that conflicts with their discovery requirements? The concrete case is a public class marked with Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute in an executable test project.

Ideally, unrelated public helper/application types would remain analyzable rather than disabling CA1515 for the entire project.

Cross-framework policy and alternative

Special-casing only MSTest in an SDK-shipped analyzer would give it preferential treatment over other test frameworks. Please consider whether an upstream exemption should follow a consistent policy for all test frameworks with public-visibility requirements, or whether framework-aware suppression should remain the responsibility of each framework's analyzers.

We are keeping microsoft/testfx#12528 open to consider a targeted DiagnosticSuppressor in MSTest.Analyzers, independently of the SDK decision. That approach can also help users of existing SDK/analyzer versions.

Prior discussion

dotnet/roslyn-analyzers#7192 (CA1515 should ignore test projects) already discusses this across frameworks, including MSTest. That repository is now archived; this issue brings the MSTest request and the cross-framework ownership question to the current analyzer repository.

Activity

  1. added
    untriaged
    on Nov 19, 2026
  2. locked and limited conversation to collaborators on Nov 19, 2026
  3. unlocked this conversation on Nov 19, 2026
  4. added
    needs team triage
    and removed
    untriaged
    on Nov 19, 2026
  5. github-actions commented on Nov 19, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    Similar issues: none

    ➡️ Summary: The issue asks CA1515 to avoid flagging public MSTest test classes that must stay public, raising a cross-framework policy question. The team should decide whether to exempt test frameworks generally or leave it to framework suppressors.

    Generated by 🏷️ Issue Triage for #57223 · copilot · auto (Claude Sonnet 5.5) · ~14 AIC · ⌖ ~2 AIC · ⊞ 15.5K · ◷

  6. removed
    needs team triage
    on Nov 24, 2026
  7. removed their assignment
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions