[test-improver] test: add edge case tests for DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031)#9020
Conversation
…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>
There was a problem hiding this comment.
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 fromTestMethodAttribute) is treated as a test method and still triggers MSTEST0031 when usingSystem.ComponentModel.DescriptionAttribute. - Add a new “no diagnostic” test ensuring short-form
[Description]resolves to MSTest’sMicrosoft.VisualStudio.TestTools.UnitTesting.DescriptionAttributewhen 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
🧪 Test quality grade — PR #9020
This advisory comment was generated automatically. Grades are heuristic
|
Evangelink
left a comment
There was a problem hiding this comment.
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, matchingmethodSymbol.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 toMicrosoft.VisualStudio.TestTools.UnitTesting.DescriptionAttributebecauseusing Microsoft.VisualStudio.TestTools.UnitTesting;is in scope — as confirmed by the companionWhenTestMethodHasMSTestDescriptionAttribute_NoDiagnostictest).WhenTestMethodHasMSTestDescriptionAttribute_NoDiagnostic: Accurately guards against a regression whereSymbolEqualityComparer.Default.Equals(attribute.AttributeClass, systemDescriptionAttributeSymbol)might be broadened toInherits(). The absence ofusing System.ComponentModel;ensures[Description]resolves to the MSTest attribute, which is a different symbol fromSystem.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} · ◷
🤖 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:[DataTestMethod]+[System.ComponentModel.Description]→ diagnostic —DataTestMethodAttributeinherits fromTestMethodAttribute. The analyzer detects test methods viaattribute.AttributeClass.Inherits(testMethodAttributeSymbol), so[DataTestMethod]should trigger the same diagnostic as[TestMethod]. No test confirmed this inheritance path.[TestMethod]+ MSTest's[Description]→ no diagnostic — Whenusing Microsoft.VisualStudio.TestTools.UnitTestingis in scope (withoutusing System.ComponentModel), the short-form[Description]resolves toMicrosoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute— the correct attribute. The analyzer checks viaSymbolEqualityComparer.Default.Equals(attribute.AttributeClass, systemDescriptionAttributeSymbol)(notInherits()), 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 toDoNotUseSystemDescriptionAttributeAnalyzerTests. No production code changes.Test Status
✅ All 7 tests pass (
MSTest.Analyzers.UnitTests, net8.0, Debug — 5 original + 2 new).Reproducibility
Trade-offs
[DataTestMethod]test pins theInherits()check behavior for derived test-method attributes.[Description]test guards against accidentally flagging the correct usage.Add this agentic workflows to your repo
To install this agentic workflow, run