[test-improver] test: add edge case tests for DoNotUseSystemDescriptionAttributeAnalyzer (MSTEST0031)#9020
Draft
Evangelink wants to merge 1 commit into
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>
Contributor
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
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
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