[test-improver] test: add edge case tests for PreferTestMethodOverDataTestMethodAnalyzer (MSTEST0044)#8885
Merged
Evangelink merged 1 commit intoJun 7, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
This was referenced Jun 7, 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
PreferTestMethodOverDataTestMethodAnalyzer(MSTEST0044) had 6 tests. Three behavioral boundaries were untested:[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.[TestClass]— the analyzer does not gate on test-class context; the diagnostic fires regardless of whether the containing class is a test class.AnalyzeNamedTypepath usesEquals(namedTypeSymbol.BaseType, ...)(not.Inherits(...)), so only direct children ofDataTestMethodAttributeare flagged; a grandchild class is not.Approach
Added three new tests to
PreferTestMethodOverDataTestMethodAnalyzerTests.cs:WhenDataTestMethodUsedWithDataRowAttribute_FixerPreservesDataRow[DataRow]siblingsWhenDataTestMethodUsedOutsideTestClass_Diagnostic[TestClass]methodsWhenClassInheritsTwoLevelsFromDataTestMethod_OnlyDirectInheritanceIsFlaggedDataTestMethodAttributeinheritance is flaggedTest Status
Trade-offs
sealedintermediate class (required so it can be subclassed), matching the real-world scenario.Add this agentic workflows to your repo
To install this agentic workflow, run