Skip to content

test: add edge-case tests for TestClassShouldBeValidAnalyzer static-class guard - #9967

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/test-classshould-be-valid-static-guard
Jul 15, 2026
Merged

test: add edge-case tests for TestClassShouldBeValidAnalyzer static-class guard#9967
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/test-classshould-be-valid-static-guard

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

Fixes#9951.

The TestClassShouldBeValidAnalyzer (MSTEST0002) static-class validation branch had two untested paths. This adds two focused tests to TestClassShouldBeValidAnalyzerTests:

  • WhenStaticTestClassContainsDerivedTestMethodAttribute_Diagnostic — a static [TestClass] with [DataTestMethod] (a TestMethodAttribute subclass) fires MSTEST0002, exercising the attribute.AttributeClass.Inherits(testMethodAttributeSymbol) branch of the static-class guard.
  • WhenStaticTestClassContainsGlobalTestInitialize_NoDiagnostic — a static [TestClass] with only [GlobalTestInitialize] does NOT fire, confirming the guard intentionally omits GlobalTestInitialize from its checked attribute set (TestInitialize, TestCleanup, ClassInitialize, ClassCleanup, and TestMethod-derived).

Test status

Full MSTest.Analyzers.UnitTests suite passes on net472 and net8.0.

…lass guard
Add two tests exercising the static-class validation branch:
- WhenStaticTestClassContainsDerivedTestMethodAttribute_Diagnostic: verifies
that a static [TestClass] with [DataTestMethod] (a TestMethodAttribute
subclass) fires MSTEST0002, covering the Inherits() path in the guard.
- WhenStaticTestClassContainsGlobalTestInitialize_NoDiagnostic: verifies
that a static [TestClass] containing only [GlobalTestInitialize] is NOT
flagged, because the guard does not check GlobalTestInitialize.
Fixes#9951
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c14361de-c664-4634-9fc2-cc3362fd2cea
CopilotAI review requested due to automatic review settings July 15, 2026 08:43

CopilotAI 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.

Pull request overview

Adds focused MSTEST0002 coverage for static test-class edge cases.

Changes:

  • Verifies derived TestMethodAttribute usage triggers the diagnostic.
  • Verifies GlobalTestInitialize alone does not trigger it.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.csAdds diagnostic and no-diagnostic edge-case tests.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #9967

GradeTestNotes
B (80–89)new TestClassShouldBeValidAnalyzerTests.
WhenStaticTestClassContainsDerivedTestMethodAttribute_
Diagnostic
Strong multi-facet assertion via VerifyCodeFixAsync; body is slightly over 30 lines — consider trimming unnecessary boilerplate in the code/fixedCode strings.
A (90–100)new TestClassShouldBeValidAnalyzerTests.
WhenStaticTestClassContainsGlobalTestInitialize_
NoDiagnostic
No issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
allowed:
- defaults
- "awmgmcpg"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · 33.1 AIC · ⌖ 6.07 AIC · ⊞ 8.9K · [◷]( · )

@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jul 15, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit f7adf47 into mainJul 15, 2026
41 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/test-classshould-be-valid-static-guard branch July 15, 2026 12:45
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-reviewAwaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test-improver] test: add edge-case tests for TestClassShouldBeValidAnalyzer static-class guard

3 participants

@Evangelink@0101