Skip to content

test: add edge case tests for AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062) - #9731

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/mstest0062-edge-case-tests
Jul 8, 2026
Merged

test: add edge case tests for AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062)#9731
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/mstest0062-edge-case-tests

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes#9716

Adds three additive tests covering previously-untested paths in AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062). No production code changes.

TestCovers
WhenTestMethodHasDerivedTestMethodAttributeAndOutParam_DiagnosticAnalyzer fires + fixer removes out when a custom attribute derived from TestMethodAttribute is used; exercises the attr.AttributeClass.Inherits(...) branch
WhenTestMethodOutsideTestClassHasOutParam_DiagnosticAnalyzer fires even when the containing class lacks [TestClass] (no TestClass guard)
WhenTestMethodHasInParameter_NoDiagnosticin parameters are not flagged — the analyzer checks only RefKind.Out/RefKind.Ref

Test status

Debug build: 0 warnings, 0 errors. MSTest.Analyzers.UnitTests pass on both net472 and net8.0 (7 pre-existing + 3 new).

… (MSTEST0062)
Three new tests covering previously-untested code paths:
- WhenTestMethodHasDerivedTestMethodAttributeAndOutParam_Diagnostic:
exercises the 'Inherits' branch via a custom attribute derived from
TestMethodAttribute.
- WhenTestMethodOutsideTestClassHasOutParam_Diagnostic:
verifies the analyzer fires even without a [TestClass] guard.
- WhenTestMethodHasInParameter_NoDiagnostic:
verifies 'in' parameters are not flagged (only RefKind.Out/Ref).
Fixes#9716
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings July 8, 2026 11:23

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

This PR adds three additive unit tests to AvoidOutRefTestMethodParametersAnalyzerTests.cs to cover previously-untested code paths in AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062). There are no production code changes. The new tests exercise the attr.AttributeClass.Inherits(...) branch (custom derived TestMethodAttribute), the absence of a [TestClass] guard, and the fact that in parameters are intentionally not flagged. I verified each test against the analyzer (only RefKind.Out/RefKind.Ref are flagged) and the fixer (which only strips out/ref keywords, leaving the s = ""; bodies valid).

Changes:

  • Add WhenTestMethodHasDerivedTestMethodAttributeAndOutParam_Diagnostic covering the inheritance-based attribute detection path.
  • Add WhenTestMethodOutsideTestClassHasOutParam_Diagnostic confirming the analyzer fires without a [TestClass] guard.
  • Add WhenTestMethodHasInParameter_NoDiagnostic confirming in parameters are not flagged.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/AvoidOutRefTestMethodParametersAnalyzerTests.csAdds three edge-case tests; correct and consistent with existing test structure, aside from a minor OutParam vs OutParameter naming inconsistency in two method names.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Medium

@github-actions

This comment has been minimized.

@github-actionsgithub-actionsBot 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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

Result: LGTM — no issues found across all evaluated dimensions.

DimensionVerdict
Correctness✅ Clean
Test Isolation✅ Clean
Assertions✅ Clean
Flakiness Risk✅ Clean
Consistency✅ Clean
Data-Driven / Parameterization✅ Clean

22 dimensions evaluated, 0 findings.

All three new tests correctly exercise previously-untested paths in the analyzer:

  • Derived attribute: exercises Inherits() resolution at analyzer line 58.
  • Outside TestClass: confirms the analyzer has no [TestClass] guard (by design — it keys only on [TestMethod]-derived attributes).
  • in parameter: confirms the RefKind.Out or RefKind.Ref check correctly excludes RefKind.In.

Tests follow established naming, structure, and assertion patterns. No shared state, no flakiness vectors.

Addresses PR review feedback.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings July 8, 2026 11:52

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: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #9731

GradeTestNotes
B (80–89)new AvoidOutRefTestMethodParametersAnalyzerTests.
WhenTestMethodHasDerivedTestMethodAttributeAndOutParameter_
Diagnostic
Body is ~41 lines (code + fixedCode pair) slightly over the ~30-line guideline — consider trimming the inline snippets for easier reading.
A (90–100)new AvoidOutRefTestMethodParametersAnalyzerTests.
WhenTestMethodHasInParameter_
NoDiagnostic
No issues found.
A (90–100)new AvoidOutRefTestMethodParametersAnalyzerTests.
WhenTestMethodOutsideTestClassHasOutParameter_
Diagnostic
No 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. Generated by the Grade Tests on PR (on open / sync) workflow. · 63.1 AIC · ⌖ 7.46 AIC · ⊞ 9.5K · [◷]( · )

@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jul 8, 2026
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 8, 2026 12:03
@Evangelink
Amaury Levé (Evangelink) merged commit 07504e3 into mainJul 8, 2026
53 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/mstest0062-edge-case-tests branch July 8, 2026 13:56
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test-improver] test: add edge case tests for AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062)

3 participants

@Evangelink@0101