[test-improver] test: add edge case tests for UseRetryWithTestMethodAnalyzer (MSTEST0035)#8909
Merged
Evangelink merged 1 commit intoJun 8, 2026
Conversation
…035) Add three new tests covering scenarios not previously exercised: - WhenDataTestMethodHasRetryAttribute_NoDiagnostic: verifies that [DataTestMethod] (which inherits TestMethodAttribute) is correctly treated as a test method, so [Retry] on it should not be flagged. - WhenTestInitializeHasRetryAttribute_Diagnostic: verifies that [TestInitialize] is a fixture method (not a test method), so [Retry] on it should be flagged. - WhenMethodInNonTestClassHasRetryAttribute_Diagnostic: verifies that [Retry] on a method inside a class with no [TestClass] attribute is also flagged, not just methods inside test classes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands the unit test coverage for the MSTest analyzer UseRetryWithTestMethodAnalyzer (MSTEST0035) by adding edge-case scenarios to prevent regressions around what constitutes a valid “test method” target for [Retry].
Changes:
- Added a no-diagnostic test ensuring
[DataTestMethod](which derives fromTestMethodAttribute) is treated as a valid target for[Retry]. - Added a diagnostic test ensuring fixture methods like
[TestInitialize]are flagged when annotated with[Retry]. - Added a diagnostic test ensuring methods in non-
[TestClass]helper classes are still flagged when annotated with[Retry].
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/UseRetryWithTestMethodAnalyzerTests.cs | Adds three edge-case tests covering [DataTestMethod], [TestInitialize], and non-test-class methods annotated with [Retry]. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Member
Author
|
/review |
Contributor
|
❌ Expert Code Review (command) failed. Please review the logs for details. |
This was referenced Jun 8, 2026
This was referenced Jun 15, 2026
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.
🤖 Test Improver — automated AI assistant focused on improving tests for this repository.
Goal and Rationale
UseRetryWithTestMethodAnalyzer(MSTEST0035) had only 7 tests covering the basic "retry on test method" and "retry on test class" paths, but missed several real-world scenarios:[DataTestMethod]with[Retry]—DataTestMethodAttributeinherits fromTestMethodAttribute. Without a test for this, a refactor of the inheritance check could silently start reporting[DataTestMethod]methods as false positives.[TestInitialize]with[Retry]— Fixture methods are not test methods. A developer might accidentally put[Retry]on a[TestInitialize]method expecting it to retry; the analyzer should flag this.[Retry]— The existing diagnostic test only covered methods inside a[TestClass]. A method in a helper class with no[TestClass]decorator should also be flagged.Approach
WhenDataTestMethodHasRetryAttribute_NoDiagnostic: confirms theInherits(testMethodAttributeSymbol)check correctly covers theDataTestMethod → TestMethodinheritance chain.WhenTestInitializeHasRetryAttribute_Diagnostic: confirms fixture attributes do not satisfy the "test method" guard.WhenMethodInNonTestClassHasRetryAttribute_Diagnostic: confirms the method-level check fires regardless of whether the containing class is a[TestClass].Coverage Impact
Not measured separately; these tests exercise existing analyzer code paths with no production changes.
Test Status
✅ All 10 tests passed (
MSTest.Analyzers.UnitTestsnet8.0):Reproducibility
Add this agentic workflows to your repo
To install this agentic workflow, run