Uh oh!
There was an error while loading. Please reload this page.
[test-improver] test: add edge case tests for UseAttributeOnTestMethodAnalyzer (MSTEST0007) - #9516
Conversation
…T0007) Add 2 new tests covering untested code paths: - WhenMethodIsMarkedWithDataTestMethodAndTestAttribute_NoDiagnosticAsync: Verifies the analyzer's early-return path fires for the standard [DataTestMethod] attribute (which inherits TestMethodAttribute), not just for custom TestMethod subclasses. - WhenMethodIsMarkedWithOSConditionAttributeButNotWithTestMethod_DiagnosticAsync: Verifies that a non-[Ignore] ConditionBase subclass ([OSCondition]) on a method without [TestMethod] fires ConditionBaseRule with the concrete class name 'OSConditionAttribute' as the message argument. Previously only [Ignore] was tested for this code path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds targeted unit tests to improve coverage for UseAttributeOnTestMethodAnalyzer (MSTEST0007) in the MSTest analyzers test suite, specifically exercising previously untested branches around DataTestMethod inheritance and ConditionBaseAttribute-derived conditions.
Changes:
- Add a no-diagnostic test validating the analyzer’s early-return behavior when
[DataTestMethod]is present (as aTestMethodAttributesubclass). - Add a diagnostic + code-fix test validating the
ConditionBaseRulepath for[OSCondition(...)]when[TestMethod]is missing.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs | Adds two new test methods to cover DataTestMethodAttribute early-return and non-IgnoreConditionBaseAttribute diagnostic behavior. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Low
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Amaury Levé (Evangelink)
commented
Jun 30, 2026
🧪 Test quality grade — PR #9516
This advisory comment was generated automatically. Grades are heuristic
|
Amaury Levé (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
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ✅ LGTM |
| 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 | ✅ LGTM |
| 11 | Assertion Quality | ✅ LGTM |
| 12 | Flakiness Patterns | ✅ LGTM |
| 13 | Test Completeness & Coverage | ✅ LGTM |
| 14 | Data-Driven Test Coverage | ✅ LGTM |
| 15 | Code Structure & Simplification | ✅ LGTM |
| 16 | Naming & Conventions | ✅ LGTM |
| 17 | Documentation Accuracy | ✅ LGTM |
| 18 | Analyzer & Code Fix Quality | ✅ LGTM |
| 19 | IPC Wire Compatibility | N/A |
| 20 | Build Infrastructure & Dependencies | N/A |
| 21 | Scope & PR Discipline | ✅ LGTM |
| 22 | PowerShell Scripting Hygiene | N/A |
Notes
Test 1 (WhenMethodIsMarkedWithDataTestMethodAndOwnerAttribute_NoDiagnosticAsync) — Correctly validates the early-return path in AnalyzeSymbol. DataTestMethodAttribute inherits TestMethodAttribute, so methodAttribute.AttributeClass.Inherits(testMethodAttributeSymbol) returns true and the method exits before collecting any diagnostics — regardless of attribute ordering in GetAttributes(). The [Owner("owner")] companion attribute is a suitable witness that a diagnostic would have been emitted had the early-return not triggered. Clean.
Test 2 (WhenMethodIsMarkedWithOSConditionAttributeButNotWithTestMethod_DiagnosticAsync) — Correctly exercises the ReferenceEquals(attribute.Rule, ConditionBaseRule) branch for a non-[Ignore] subclass. OSConditionAttribute : ConditionBaseAttribute is confirmed in source; OperatingSystems.Windows is a valid enum value in Microsoft.VisualStudio.TestTools.UnitTesting; attribute.AttributeData.AttributeClass.Name yields "OSConditionAttribute", matching .WithArguments("OSConditionAttribute"). The code fix expectation (inserting [TestMethod] below the condition attribute) is consistent with the fixer's existing behaviour verified by the [Ignore] analogue. Clean.
Pre-existing observation (not introduced by this PR)
ConditionBaseRule is absent from SupportedDiagnostics (line 119–125 of UseAttributeOnTestMethodAnalyzer.cs), while it is present in RuleTuples. This does not cause a runtime failure because all six rule descriptors share the same DiagnosticIds.UseAttributeOnTestMethodRuleId ID, and Roslyn filters by ID when deciding whether a reported diagnostic is supported. However, the missing entry means IDE tooling cannot surface ConditionBaseRule's distinct title/message-format in the analyzer catalog. The existing [Ignore] test — and now the new OSCondition test — both exercise this descriptor without issue, confirming the gap is benign in practice. Worth tracking separately if full descriptor fidelity in the manifest matters.
Uh oh!
There was an error while loading. Please reload this page.
Goal and Rationale
UseAttributeOnTestMethodAnalyzer(MSTEST0007) had 37 test cases via 11 test methods (several usingDynamicData), but two distinct code paths in the analyzer's logic were not covered:[DataTestMethod]causes early-return (no diagnostic)methodAttribute.AttributeClass.Inherits(testMethodAttributeSymbol)early-return — previously only tested with a customMyCustomTestMethodAttribute[Ignore]ConditionBasesubclass firesConditionBaseRulewith the concrete class nameReferenceEquals(attribute.Rule, ConditionBaseRule)→attribute.AttributeData.AttributeClass.Name— previously only[Ignore]was testedApproach
Added two
[TestMethod]entries toUseAttributeOnTestMethodAnalyzerTests.cs:WhenMethodIsMarkedWithDataTestMethodAndTestAttribute_NoDiagnosticAsync[DataTestMethod]+[Owner("owner")]→ no diagnostic. Validates that the standardDataTestMethodAttribute(which inheritsTestMethodAttribute) also causes early-return in the analyzer, not just user-defined subclasses.WhenMethodIsMarkedWithOSConditionAttributeButNotWithTestMethod_DiagnosticAsync[OSCondition(OperatingSystems.Windows)]on a method with no[TestMethod]→ConditionBaseRulewith argument"OSConditionAttribute". Validates theConditionBaseRulebranch for a non-[Ignore]subclass ofConditionBaseAttribute.Coverage Impact
UseAttributeOnTestMethodAnalyzerTestsTrade-offs
Purely additive — no production code changes, no new dependencies.
Test Status
All 39/39 tests pass (
net8.0,Debug):Reproducibility
Add this agentic workflows to your repo
To install this agentic workflow, run