Skip to content

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

Description

@github-actions

Goal and Rationale

AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062) had 7 tests covering the direct happy-path scenarios. Three distinct guard/classification paths in the analyzer were not yet covered by tests:

Untested pathCode in analyzer
TestMethodAttribute inheritance checkattr.AttributeClass.Inherits(testMethodAttributeSymbol)
No [TestClass] guard (fires outside test classes)absent
RefKind.In not flaggedp.RefKind is RefKind.Out or RefKind.Ref

Approach

Three additive tests, no production code changes:

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

Test Status

Debug build: 0 warnings, 0 errors. AvoidOutRefTestMethodParametersAnalyzerTests on net8.0: 10/10 passed (7 pre-existing + 3 new).

🤖 Automated content by GitHub Copilot. Generated by the Test Improver workflow. · 168.3 AIC · ⌖ 16.3 AIC · ⊞ 13K · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch test-assist/avoid-out-ref-edge-cases-9c17117d3f8f0d79.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (131 of 131 lines)
From af26c774a8713cb68394426719c2d742adecfce5 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 7 Jul 2026 23:24:17 +0000
Subject: [PATCH] test: add edge case tests for
AvoidOutRefTestMethodParametersAnalyzer (MSTEST0062)
Three new tests covering previously-untested code paths:
- WhenTestMethodHasDerivedTestMethodAttributeAndOutParam_Diagnostic:
verify the analyzer fires (and fixer removes 'out') when the test method
carries a custom attribute derived from TestMethodAttribute rather than
TestMethodAttribute directly; exercises the 'Inherits' branch.
- WhenTestMethodOutsideTestClassHasOutParam_Diagnostic:
verify the analyzer fires even when the containing class has no
[TestClass] attribute (the analyzer has no TestClass guard).
- WhenTestMethodHasInParameter_NoDiagnostic:
verify 'in' parameters are not flagged; the analyzer explicitly checks
only RefKind.Out and RefKind.Ref.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
...OutRefTestMethodParametersAnalyzerTests.cs | 92 +++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidOutRefTestMethodParametersAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidOutRefTestMethodParametersAnalyzerTests.cs
index b1dd593..0b7bb28 100644
--- a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidOutRefTestMethodParametersAnalyzerTests.cs+++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidOutRefTestMethodParametersAnalyzerTests.cs@@ -230,4 +230,96 @@ public void TestMethod1(string s)
await VerifyCS.VerifyCodeFixAsync(code, fixedCode);
}
++ [TestMethod]+ public async Task WhenTestMethodHasDerivedTestMethodAttributeAndOutParam_Diagnostic()+ {+ string code = """+ using Microsoft.VisualStudio.TestTools.UnitTesting;++ public sealed class MyCustomTestMethodAttribute : TestMethodAttribute { }++
... (truncated)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentic-workflowsGitHub agentic workflow definitions under .github/workflows/*.md.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions