Skip to content

[test-improver] test: add edge case tests for DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031)#9020

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/donotuseSystemDescription-edge-cases-58ec96c06026a682
Jun 11, 2026
Merged

[test-improver] test: add edge case tests for DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031)#9020
Evangelink merged 1 commit into
mainfrom
test-assist/donotuseSystemDescription-edge-cases-58ec96c06026a682

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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

Goal and Rationale

DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031) had 5 tests covering the main diagnostic and code-fix paths, but two real-world behaviors were undocumented:

  1. [DataTestMethod] + [System.ComponentModel.Description] → diagnosticDataTestMethodAttribute inherits from TestMethodAttribute. The analyzer detects test methods via attribute.AttributeClass.Inherits(testMethodAttributeSymbol), so [DataTestMethod] should trigger the same diagnostic as [TestMethod]. No test confirmed this inheritance path.

  2. [TestMethod] + MSTest's [Description] → no diagnostic — When using Microsoft.VisualStudio.TestTools.UnitTesting is in scope (without using System.ComponentModel), the short-form [Description] resolves to Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute — the correct attribute. The analyzer checks via SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, systemDescriptionAttributeSymbol) (not Inherits()), so it must not fire here. This test guards against a future regression that might accidentally flag the correct usage.

Approach

Added 2 new [TestMethod] test cases to DoNotUseSystemDescriptionAttributeAnalyzerTests. No production code changes.

Test Status

Test run summary: Passed!
  total: 7
  failed: 0
  succeeded: 7
  skipped: 0
  duration: 8s 605ms

✅ All 7 tests pass (MSTest.Analyzers.UnitTests, net8.0, Debug — 5 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.DoNotUseSystemDescriptionAttributeAnalyzerTests"

Trade-offs

  • Tests exercise existing code paths only — no production changes, no maintenance burden beyond the tests.
  • The [DataTestMethod] test pins the Inherits() check behavior for derived test-method attributes.
  • The MSTest [Description] test guards against accidentally flagging the correct usage.

🤖 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.{ai_credits_suffix} · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

…zer (MSTEST0031)

Add two new test cases:
- [DataTestMethod] + [System.ComponentModel.Description] → diagnostic (confirms
  Inherits() catches attributes derived from TestMethodAttribute)
- [TestMethod] + MSTest's [Description] (no System.ComponentModel using) → no
  diagnostic (resolves to the correct MSTest attribute)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 10, 2026 23:38
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 10, 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 unit test coverage for the DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031) in MSTest.Analyzers.UnitTests by adding two edge-case tests that document and lock in real-world attribute resolution/inheritance behavior.

Changes:

  • Add a new diagnostic + code-fix test ensuring [DataTestMethod] (derived from TestMethodAttribute) is treated as a test method and still triggers MSTEST0031 when using System.ComponentModel.DescriptionAttribute.
  • Add a new “no diagnostic” test ensuring short-form [Description] resolves to MSTest’s Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute when only the MSTest namespace is imported, and is not incorrectly flagged.
Show a summary per file
File Description
test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseSystemDescriptionAttributeAnalyzerTests.cs Adds two edge-case unit tests covering DataTestMethod inheritance detection and MSTest [Description] short-name resolution without triggering the analyzer.

Copilot's findings

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

@Evangelink Evangelink marked this pull request as ready for review June 11, 2026 07:25
@Evangelink Evangelink merged commit ff16015 into main Jun 11, 2026
31 of 40 checks passed
@Evangelink Evangelink deleted the test-assist/donotuseSystemDescription-edge-cases-58ec96c06026a682 branch June 11, 2026 07:25
@Evangelink

Copy link
Copy Markdown
Member Author

🧪 Test quality grade — PR #9020

ΔTestGradeBandNotes
new DoNotUseSystemDescriptionAttributeAnalyzerTests.
WhenDataTestMethodHasSystemDescriptionAttribute_
Diagnostic
A 90–100 VerifyCodeFixAsync asserts diagnostic location and fix output; comment explains DataTestMethod inheritance rationale.
new DoNotUseSystemDescriptionAttributeAnalyzerTests.
WhenTestMethodHasMSTestDescriptionAttribute_
NoDiagnostic
A 90–100 No-diagnostic test; VerifyAnalyzerAsync asserts analyzer is silent for MSTest-namespaced Description attribute.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 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 Grade Tests on PR (on open / sync) workflow.{ai_credits_suffix} · [◷]( · )

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Automated review 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 Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

✅ 22/22 dimensions clean — no findings.

Dimension coverage notes (test-only PR)
# Dimension Status
1 Algorithmic Correctness ✅ Clean
2 Threading & Concurrency — N/A
3 Security & IPC Contract Safety — N/A
4 Public API & Binary Compatibility — N/A
5 Performance & Allocations — N/A
6 Cross-TFM Compatibility — N/A
7 Resource & IDisposable Management — N/A
8 Defensive Coding at Boundaries — N/A
9 Localization & Resources — N/A
10 Test Isolation ✅ Clean
11 Assertion Quality ✅ Clean
12 Flakiness Patterns ✅ Clean
13 Test Completeness & Coverage ✅ Clean
14 Data-Driven Test Coverage ✅ Clean
15 Code Structure & Simplification ✅ Clean
16 Naming & Conventions ✅ Clean
17 Documentation Accuracy ✅ Clean
18 Analyzer & Code Fix Quality — N/A (no src/Analyzers change)
19 IPC Wire Compatibility — N/A
20 Build Infrastructure & Dependencies — N/A
21 Scope & PR Discipline ✅ Clean
22 PowerShell Scripting Hygiene — N/A

Notable verifications:

  • WhenDataTestMethodHasSystemDescriptionAttribute_Diagnostic: The [|MyTestMethod|] diagnostic marker correctly targets the method name, matching methodSymbol.CreateDiagnostic(..., methodSymbol.Name) in the analyzer. The code fix correctly preserves [DataRow(1)] and replaces [System.ComponentModel.Description(...)] with the short-form [Description(...)] (which resolves to Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute because using Microsoft.VisualStudio.TestTools.UnitTesting; is in scope — as confirmed by the companion WhenTestMethodHasMSTestDescriptionAttribute_NoDiagnostic test).
  • WhenTestMethodHasMSTestDescriptionAttribute_NoDiagnostic: Accurately guards against a regression where SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, systemDescriptionAttributeSymbol) might be broadened to Inherits(). The absence of using System.ComponentModel; ensures [Description] resolves to the MSTest attribute, which is a different symbol from System.ComponentModel.DescriptionAttribute, so the analyzer correctly stays silent.
  • Comments in both tests accurately describe the Inherits() vs. SymbolEqualityComparer.Default.Equals() distinction, providing valuable context for future contributors.

🤖 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 Expert Code Review (on PR ready) workflow.{ai_credits_suffix} ·

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