test: add edge-case tests for TestClassShouldBeValidAnalyzer static-class guard - #9967
Merged
Evangelink merged 1 commit intoJul 15, 2026
Merged
Conversation
…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
Contributor
There was a problem hiding this comment.
Pull request overview
Adds focused MSTEST0002 coverage for static test-class edge cases.
Changes:
- Verifies derived
TestMethodAttributeusage triggers the diagnostic. - Verifies
GlobalTestInitializealone does not trigger it.
Show a summary per file
| File | Description |
|---|---|
test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.cs |
Adds diagnostic and no-diagnostic edge-case tests. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Medium
Contributor
🧪 Test quality grade — PR #9967
This advisory comment was generated automatically. Grades are heuristic Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
0101
approved these changes
Jul 15, 2026
Evangelink
enabled auto-merge (squash)
July 15, 2026 10:58
Evangelink
deleted the
dev/amauryleve/test-classshould-be-valid-static-guard
branch
July 15, 2026 12:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #9951.
The
TestClassShouldBeValidAnalyzer(MSTEST0002) static-class validation branch had two untested paths. This adds two focused tests toTestClassShouldBeValidAnalyzerTests:WhenStaticTestClassContainsDerivedTestMethodAttribute_Diagnostic— a static[TestClass]with[DataTestMethod](aTestMethodAttributesubclass) fires MSTEST0002, exercising theattribute.AttributeClass.Inherits(testMethodAttributeSymbol)branch of the static-class guard.WhenStaticTestClassContainsGlobalTestInitialize_NoDiagnostic— a static[TestClass]with only[GlobalTestInitialize]does NOT fire, confirming the guard intentionally omitsGlobalTestInitializefrom its checked attribute set (TestInitialize,TestCleanup,ClassInitialize,ClassCleanup, andTestMethod-derived).Test status
Full
MSTest.Analyzers.UnitTestssuite passes onnet472andnet8.0.