Skip to content

[test-improver] test: add edge case tests for PreferTestMethodOverDataTestMethodAnalyzer (MSTEST0044)#8885

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/prefer-test-method-edge-cases-2f6b2f74687d26a7
Jun 7, 2026
Merged

[test-improver] test: add edge case tests for PreferTestMethodOverDataTestMethodAnalyzer (MSTEST0044)#8885
Evangelink merged 1 commit into
mainfrom
test-assist/prefer-test-method-edge-cases-2f6b2f74687d26a7

Conversation

@Evangelink

Copy link
Copy Markdown
Member

🤖 Test Improver — automated AI assistant focused on improving tests for this repository.

Goal and Rationale

PreferTestMethodOverDataTestMethodAnalyzer (MSTEST0044) had 6 tests. Three behavioral boundaries were untested:

  1. Fixer + [DataRow] coexistence — developers often use [DataTestMethod] because they think it's required for [DataRow] to work; the fixer should replace it with [TestMethod] while leaving all [DataRow] attributes untouched.
  2. Method outside [TestClass] — the analyzer does not gate on test-class context; the diagnostic fires regardless of whether the containing class is a test class.
  3. Two-level inheritance — the AnalyzeNamedType path uses Equals(namedTypeSymbol.BaseType, ...) (not .Inherits(...)), so only direct children of DataTestMethodAttribute are flagged; a grandchild class is not.

Approach

Added three new tests to PreferTestMethodOverDataTestMethodAnalyzerTests.cs:

Test What it exercises
WhenDataTestMethodUsedWithDataRowAttribute_FixerPreservesDataRow Code-fix preserves [DataRow] siblings
WhenDataTestMethodUsedOutsideTestClass_Diagnostic Diagnostic fires on non-[TestClass] methods
WhenClassInheritsTwoLevelsFromDataTestMethod_OnlyDirectInheritanceIsFlagged Only direct DataTestMethodAttribute inheritance is flagged

Test Status

Test run summary: Passed! (net8.0|x64)
  total: 9
  failed: 0
  succeeded: 9
  skipped: 0

Trade-offs

  • No production code changes — tests only.
  • The two-level inheritance test uses a non-sealed intermediate class (required so it can be subclassed), matching the real-world scenario.

Generated by Test Improver · sonnet46 5.3M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

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

…zer (MSTEST0044)

Add 3 new edge case tests for PreferTestMethodOverDataTestMethodAnalyzer:

1. WhenDataTestMethodUsedWithDataRowAttribute_FixerPreservesDataRow — verifies
   that the code fixer replaces [DataTestMethod] with [TestMethod] while
   preserving co-existing [DataRow] attributes unchanged.

2. WhenDataTestMethodUsedOutsideTestClass_Diagnostic — confirms the analyzer
   fires on [DataTestMethod] on a method even when the containing class has no
   [TestClass] attribute, since the rule applies regardless of test-class context.

3. WhenClassInheritsTwoLevelsFromDataTestMethod_OnlyDirectInheritanceIsFlagged —
   documents that the analyzer only checks *direct* base-type equality to
   DataTestMethodAttribute, so a grandchild class (inheriting from a class that
   already inherits DataTestMethodAttribute) does NOT produce a diagnostic.

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

Adds targeted unit tests for the MSTest analyzer MSTEST0044 (PreferTestMethodOverDataTestMethodAnalyzer) to cover previously untested behavioral boundaries in the analyzer + code fix.

Changes:

  • Adds a code-fix test ensuring [DataRow] attributes are preserved when [DataTestMethod] is replaced with [TestMethod].
  • Adds a diagnostic + code-fix test confirming the analyzer fires even when the containing class is not marked [TestClass].
  • Adds an analyzer scenario test covering two-level inheritance from DataTestMethodAttribute (only the direct child should be flagged).
Show a summary per file
File Description
test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestMethodOverDataTestMethodAnalyzerTests.cs Adds three new edge-case tests for MSTEST0044 covering fixer behavior, non-test-class methods, and direct-vs-indirect inheritance.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

@Evangelink Evangelink marked this pull request as ready for review June 7, 2026 07:19
@Evangelink Evangelink enabled auto-merge (squash) June 7, 2026 07:19
@Evangelink Evangelink disabled auto-merge June 7, 2026 11:08
@Evangelink Evangelink merged commit ab219db into main Jun 7, 2026
44 checks passed
@Evangelink Evangelink deleted the test-assist/prefer-test-method-edge-cases-2f6b2f74687d26a7 branch June 7, 2026 11:08
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