Skip to content

[test-improver] test: add edge case tests for UseRetryWithTestMethodAnalyzer (MSTEST0035)#8909

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/retry-analyzer-edge-cases-cf50dc786c1b0fe1
Jun 8, 2026
Merged

[test-improver] test: add edge case tests for UseRetryWithTestMethodAnalyzer (MSTEST0035)#8909
Evangelink merged 1 commit into
mainfrom
test-assist/retry-analyzer-edge-cases-cf50dc786c1b0fe1

Conversation

@Evangelink

Copy link
Copy Markdown
Member

🤖 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:

  1. [DataTestMethod] with [Retry]DataTestMethodAttribute inherits from TestMethodAttribute. Without a test for this, a refactor of the inheritance check could silently start reporting [DataTestMethod] methods as false positives.
  2. [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.
  3. Method in a non-test class with [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

  • Added WhenDataTestMethodHasRetryAttribute_NoDiagnostic: confirms the Inherits(testMethodAttributeSymbol) check correctly covers the DataTestMethod → TestMethod inheritance chain.
  • Added WhenTestInitializeHasRetryAttribute_Diagnostic: confirms fixture attributes do not satisfy the "test method" guard.
  • Added 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.UnitTests net8.0):

Test run summary: Passed!
  total: 10
  failed: 0
  succeeded: 10
  skipped: 0
  duration: 6s 128ms

Reproducibility

./build.sh --restore   # first run only, installs .NET SDK
.dotnet/dotnet test test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj \
  -f net8.0 --no-build -c Debug \
  --filter "ClassName=MSTest.Analyzers.Test.UseRetryWithTestMethodAnalyzerTests"

Generated by Test Improver · sonnet46 7.6M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@main

…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>
Copilot AI review requested due to automatic review settings June 7, 2026 23:31
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 7, 2026

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.

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 from TestMethodAttribute) 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

@Evangelink Evangelink marked this pull request as ready for review June 8, 2026 07:54
@Evangelink

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Expert Code Review (command) failed. Please review the logs for details.

@Evangelink Evangelink merged commit cd3bbf4 into main Jun 8, 2026
44 checks passed
@Evangelink Evangelink deleted the test-assist/retry-analyzer-edge-cases-cf50dc786c1b0fe1 branch June 8, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants