Skip to content

[test-improver] test: add DataTestMethod edge cases for TypeContainingTestMethodShouldBeATestClassAnalyzer (MSTEST0030)#9092

Draft
Evangelink wants to merge 1 commit into
mainfrom
test-assist/mstest0030-datatestmethod-edge-cases-055df8ad84c452ff
Draft

[test-improver] test: add DataTestMethod edge cases for TypeContainingTestMethodShouldBeATestClassAnalyzer (MSTEST0030)#9092
Evangelink wants to merge 1 commit into
mainfrom
test-assist/mstest0030-datatestmethod-edge-cases-055df8ad84c452ff

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

TypeContainingTestMethodShouldBeATestClassAnalyzer (MSTEST0030) flags non-test classes that contain test methods (direct or inherited). The analyzer detects test methods via attribute.AttributeClass.Inherits(testMethodAttributeSymbol), which should recognize DataTestMethodAttribute since it inherits from TestMethodAttribute. Two concrete scenarios were not explicitly tested:

  1. DataTestMethod directly on a method in a non-test class — the Inherits() check should recognize DataTestMethodAttribute as a test method, triggering the diagnostic.

  2. DataTestMethod inherited from an abstract base class — the inheritance walk (while (currentType is not null)) should traverse up to the abstract base and detect the DataTestMethod. The abstract base is exempt (per the IsAbstract guard), but the concrete derived class should fire the diagnostic.

Approach

Added two new [TestMethod] test cases to TypeContainingTestMethodShouldBeATestClassAnalyzerTests.cs:

  • WhenNonTestClassHasDataTestMethod_Diagnostic — confirms [DataTestMethod] (first-party TestMethodAttribute subclass) 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

Test run summary: Passed!
  total: 16
  failed: 0
  succeeded: 16
  skipped: 0
  duration: 7s 373ms

✅ All 16 tests pass (MSTest.Analyzers.UnitTests, net8.0, Debug — 14 original + 2 new).

Reproducibility

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

Trade-offs

  • Tests exercise existing code paths only — no production changes, no maintenance burden beyond the tests.
  • Both tests document how the Inherits() check handles DataTestMethodAttribute (the built-in TestMethodAttribute subclass), complementing the existing test for custom subclasses.

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Test Improver workflow. · 1K AIC · ⌖ 23 AIC · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

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

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