Skip to content

[test-improver] test: add edge case tests for UseAttributeOnTestMethodAnalyzer (MSTEST0007) - #9516

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/use-attribute-on-test-method-edge-cases-434677eb5a320f85
Jun 30, 2026
Merged

[test-improver] test: add edge case tests for UseAttributeOnTestMethodAnalyzer (MSTEST0007)#9516
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/use-attribute-on-test-method-edge-cases-434677eb5a320f85

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

UseAttributeOnTestMethodAnalyzer (MSTEST0007) had 37 test cases via 11 test methods (several using DynamicData), but two distinct code paths in the analyzer's logic were not covered:

Untested pathGuard
Standard [DataTestMethod] causes early-return (no diagnostic)methodAttribute.AttributeClass.Inherits(testMethodAttributeSymbol) early-return — previously only tested with a custom MyCustomTestMethodAttribute
Non-[Ignore]ConditionBase subclass fires ConditionBaseRule with the concrete class nameReferenceEquals(attribute.Rule, ConditionBaseRule)attribute.AttributeData.AttributeClass.Name — previously only [Ignore] was tested

Approach

Added two [TestMethod] entries to UseAttributeOnTestMethodAnalyzerTests.cs:

TestWhat it covers
WhenMethodIsMarkedWithDataTestMethodAndTestAttribute_NoDiagnosticAsync[DataTestMethod] + [Owner("owner")] → no diagnostic. Validates that the standard DataTestMethodAttribute (which inherits TestMethodAttribute) also causes early-return in the analyzer, not just user-defined subclasses.
WhenMethodIsMarkedWithOSConditionAttributeButNotWithTestMethod_DiagnosticAsync[OSCondition(OperatingSystems.Windows)] on a method with no [TestMethod]ConditionBaseRule with argument "OSConditionAttribute". Validates the ConditionBaseRule branch for a non-[Ignore] subclass of ConditionBaseAttribute.

Coverage Impact

BeforeAfter
Tests in UseAttributeOnTestMethodAnalyzerTests3739

Trade-offs

Purely additive — no production code changes, no new dependencies.

Test Status

All 39/39 tests pass (net8.0, Debug):

Test run summary: Passed!
total: 39
failed: 0
succeeded: 39
duration: 7s 251ms

Reproducibility

.dotnet/dotnet test test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj \
-f net8.0 --no-build -c Debug \
--filter "FullyQualifiedName~UseAttributeOnTestMethodAnalyzerTests"

🤖 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. · 2K AIC · ⌖ 25.1 AIC · ⊞ 58.2K · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

…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>
CopilotAI review requested due to automatic review settings June 29, 2026 23:32
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 29, 2026

CopilotAI 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 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 a TestMethodAttribute subclass).
  • Add a diagnostic + code-fix test validating the ConditionBaseRule path for [OSCondition(...)] when [TestMethod] is missing.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.csAdds 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

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review June 30, 2026 05:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 30, 2026 05:13
@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 30, 2026

CopilotAI 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.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Low

@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9516

ΔTestGradeBandNotes
newUseAttributeOnTestMethodAnalyzerTests.
WhenMethodIsMarkedWithOSConditionAttributeButNotWithTestMethod_
DiagnosticAsync
B80–89Body is slightly over ~30 lines (~36) due to the code-fix pattern needing both input and expected-output snippets; assertions thoroughly verify the diagnostic rule, location, arguments, and fix output.
newUseAttributeOnTestMethodAnalyzerTests.
WhenMethodIsMarkedWithDataTestMethodAndOwnerAttribute_
NoDiagnosticAsync
A90–100No issues found.

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. · 217.9 AIC · ⌖ 13.2 AIC · ⊞ 45.7K · [◷]( · )

Copy link
Copy Markdown
MemberAuthor

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
#DimensionVerdict
1Algorithmic Correctness✅ LGTM
2Threading & ConcurrencyN/A
3Security & IPC Contract SafetyN/A
4Public API & Binary CompatibilityN/A
5Performance & AllocationsN/A
6Cross-TFM CompatibilityN/A
7Resource & IDisposable ManagementN/A
8Defensive Coding at BoundariesN/A
9Localization & ResourcesN/A
10Test Isolation✅ LGTM
11Assertion Quality✅ LGTM
12Flakiness Patterns✅ LGTM
13Test Completeness & Coverage✅ LGTM
14Data-Driven Test Coverage✅ LGTM
15Code Structure & Simplification✅ LGTM
16Naming & Conventions✅ LGTM
17Documentation Accuracy✅ LGTM
18Analyzer & Code Fix Quality✅ LGTM
19IPC Wire CompatibilityN/A
20Build Infrastructure & DependenciesN/A
21Scope & PR Discipline✅ LGTM
22PowerShell Scripting HygieneN/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.

@Evangelink
Amaury Levé (Evangelink) merged commit 683d94c into mainJun 30, 2026
43 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/use-attribute-on-test-method-edge-cases-434677eb5a320f85 branch June 30, 2026 08:19
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-reviewAwaiting review from the team.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Evangelink@0101