You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
Activity
Evangelink commentedon Nov 19, 2026
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
DiagnosticSuppressorinMSTest.Analyzershere, 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.
drieseng commentedon Nov 19, 2026
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.
Evangelink commentedon Nov 19, 2026
Fixed by #12538