[test-improver] test: add DataTestMethod edge cases for TypeContainingTestMethodShouldBeATestClassAnalyzer (MSTEST0030)#9092
Draft
Evangelink wants to merge 1 commit into
Conversation
…dBeATestClassAnalyzer (MSTEST0030) Two new test cases verifying that DataTestMethodAttribute (which inherits TestMethodAttribute) is correctly recognized by the Inherits() check: 1. WhenNonTestClassHasDataTestMethod_Diagnostic – a non-test class with a [DataTestMethod] directly triggers the diagnostic and the fixer adds [TestClass]. 2. WhenNonTestClassInheritsDataTestMethodFromAbstractBase_Diagnostic – the inheritance walk correctly detects DataTestMethod from an abstract base class, firing the diagnostic only on the concrete derived class (abstract base is exempt per the IsAbstract guard). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds regression/edge-case coverage to the MSTest analyzer test suite for MSTEST0030 (TypeContainingTestMethodShouldBeATestClassAnalyzer), specifically ensuring that [DataTestMethod] is treated as a test method (via inheritance from TestMethodAttribute) both when applied directly and when inherited from an abstract base type.
Changes:
- Add a new code-fix test verifying a diagnostic is produced when a non-test class contains a
[DataTestMethod]. - Add a new code-fix test verifying the analyzer’s base-type walk detects a
[DataTestMethod]declared on an abstract base type and reports only on the concrete derived non-test class.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/TypeContainingTestMethodShouldBeATestClassAnalyzerTests.cs | Adds two new analyzer/code-fix test cases covering [DataTestMethod] direct usage and inherited-from-abstract-base scenarios for MSTEST0030. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
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.
Goal and Rationale
TypeContainingTestMethodShouldBeATestClassAnalyzer(MSTEST0030) flags non-test classes that contain test methods (direct or inherited). The analyzer detects test methods viaattribute.AttributeClass.Inherits(testMethodAttributeSymbol), which should recognizeDataTestMethodAttributesince it inherits fromTestMethodAttribute. Two concrete scenarios were not explicitly tested:DataTestMethoddirectly on a method in a non-test class — theInherits()check should recognizeDataTestMethodAttributeas a test method, triggering the diagnostic.DataTestMethodinherited from an abstract base class — the inheritance walk (while (currentType is not null)) should traverse up to the abstract base and detect theDataTestMethod. The abstract base is exempt (per theIsAbstractguard), but the concrete derived class should fire the diagnostic.Approach
Added two new
[TestMethod]test cases toTypeContainingTestMethodShouldBeATestClassAnalyzerTests.cs:WhenNonTestClassHasDataTestMethod_Diagnostic— confirms[DataTestMethod](first-partyTestMethodAttributesubclass) triggers the diagnostic and the code fix correctly adds[TestClass]WhenNonTestClassInheritsDataTestMethodFromAbstractBase_Diagnostic— confirms the inheritance walk detects[DataTestMethod]from an abstract base, firing only on the concrete derived class (abstract base is exempt)Test Status
✅ All 16 tests pass (
MSTest.Analyzers.UnitTests, net8.0, Debug — 14 original + 2 new).Reproducibility
Trade-offs
Inherits()check handlesDataTestMethodAttribute(the built-inTestMethodAttributesubclass), complementing the existing test for custom subclasses.Add this agentic workflows to your repo
To install this agentic workflow, run