Skip to content

Add diagnostic for TestClass on abstract classes - #11240

Merged
Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/report-abstract-testclass-diagnostic
Sep 13, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
microsoft:mainfrom
Evangelink:dev/amauryleve/report-abstract-testclass-diagnostic

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Applying [TestClass] to an abstract class is misleading because MSTest skips abstract types during discovery. Tests declared by the base are discovered through concrete derived test classes, which must declare their own [TestClass] attribute.

Changes

  • Add the enabled-by-default, Info-level MSTEST0085 diagnostic for [TestClass] and derived attributes applied to non-static abstract classes.
  • Keep static test classes supported for assembly fixture scenarios.
  • Add release tracking and generated localization resources.
  • Cover C#, abstract records, custom derived attributes, Visual Basic MustInherit classes, and non-diagnostic cases.

Testing

  • build.cmd -projects test\UnitTests\MSTest.Analyzers.UnitTests\MSTest.Analyzers.UnitTests.csproj -binaryLog
  • 7 focused TestClassAttributeShouldNotBeAppliedToAbstractClassAnalyzerTests passed on net8.0.

Fixes: #11236

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 13, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review tier: Lite (auto)
Findings: None

Note

Copilot is running an experiment and ran this review at Lite.

What changed in this PR

Adds MSTEST0085 to flag [TestClass] on non-static abstract classes, where it has no discovery effect.

Changes:

  • Implements the enabled Info-level analyzer and release tracking.
  • Adds C#, record, custom-attribute, VB, and non-diagnostic tests.
  • Adds resource and localization entries.
File Description
test/​UnitTests/​MSTest.Analyzers.UnitTests/​TestClassAttributeShouldNotBeAppliedToAbstractClassAnalyzerTests.cs Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.zh-Hant.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.zh-Hans.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.tr.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.ru.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.pt-BR.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.pl.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.ko.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.ja.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.it.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.fr.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.es.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.de.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​xlf/​Resources.cs.xlf Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​TestClassAttributeShouldNotBeAppliedToAbstractClassAnalyzer.cs Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​Resources.resx Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​Helpers/​DiagnosticIds.cs Updated as part of this pull request.
src/​Analyzers/​MSTest.Analyzers/​AnalyzerReleases.Unshipped.md Updated as part of this pull request.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Sep 13, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit e3293ab into microsoft:main Sep 13, 2026
36 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/report-abstract-testclass-diagnostic branch September 13, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report diagnostic when TestClassAttribute is applied to an abstract class

3 participants