Skip to content

[test-improver] test: add edge case tests for RemoveClassCleanupBehaviorArgumentFixer - #9410

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
test-assist/remove-classcleanuup-behavior-edge-cases-94eb5ef9f5cab19a
Jun 25, 2026
Merged

[test-improver] test: add edge case tests for RemoveClassCleanupBehaviorArgumentFixer#9410
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
test-assist/remove-classcleanuup-behavior-edge-cases-94eb5ef9f5cab19a

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

RemoveClassCleanupBehaviorArgumentFixer had only 2 tests covering the "happy path" (sole argument removed, second of two arguments removed). Two code paths inside the fixer were completely untested:

  1. ClassCleanupBehavior as the first of two arguments — the fixer removes the first argument and preserves the remaining InheritanceBehavior argument. This is the mirror of the existing test where ClassCleanupBehavior is second.
  2. attributeArgument is null guard — when a CS0103 diagnostic for ClassCleanupBehavior fires outside an attribute argument (e.g. in a method body), the fixer explicitly skips registration. This path was never exercised by a test.

Approach

Added two new [TestMethod] entries to RemoveClassCleanupBehaviorArgumentFixerTests.cs:

TestWhat it covers
WhenClassCleanupBehaviorIsFirstArgument_RemovesBehaviorKeepsInheritance[ClassCleanup(ClassCleanupBehavior.EndOfClass, InheritanceBehavior.None)][ClassCleanup(InheritanceBehavior.None)]
WhenClassCleanupBehaviorReferencedOutsideAttribute_NoFix_ = ClassCleanupBehavior.EndOfClass; in a method body — no fix registered, code unchanged

Trade-offs

Both tests are simple and low-maintenance. The "no fix" test uses VerifyCodeFixAsync(code, code), the same pattern used elsewhere in the codebase for cases where a diagnostic fires but no fix is appropriate.

Test Status

All 4 tests pass (2 pre-existing + 2 new):

passed WhenClassCleanupBehaviorArgument_Simple
passed WhenClassCleanupBehaviorWithMultiLineBody_PreservesIndentation
passed WhenClassCleanupBehaviorIsFirstArgument_RemovesBehaviorKeepsInheritance ← new
passed WhenClassCleanupBehaviorReferencedOutsideAttribute_NoFix ← new

Command:

.dotnet/dotnet run --project test/UnitTests/MSTest.Analyzers.UnitTests/ -f net8.0 --no-build -c Debug -- --filter "FullyQualifiedName~RemoveClassCleanupBehaviorArgumentFixerTests"

🤖 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. · 2.3K AIC · ⌖ 25.3 AIC · ⊞ 58K · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

- WhenClassCleanupBehaviorIsFirstArgument_RemovesBehaviorKeepsInheritance:
verifies that when ClassCleanupBehavior appears as the first argument
(before InheritanceBehavior), the fixer removes it and preserves the
remaining argument.
- WhenClassCleanupBehaviorReferencedOutsideAttribute_NoFix:
verifies the attributeArgument-is-null guard — the fixer does not
register a fix when ClassCleanupBehavior is used in a method body
instead of an attribute argument.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 24, 2026 23:44
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 24, 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 missing unit-test coverage for RemoveClassCleanupBehaviorArgumentFixer (MSTest analyzers) by exercising two previously untested branches: removing ClassCleanupBehavior when it is the first of two arguments, and ensuring no fix is offered when ClassCleanupBehavior appears outside an attribute argument.

Changes:

  • Add a test where ClassCleanupBehavior is the first argument and verify the fixer preserves the remaining InheritanceBehavior argument.
  • Add a test ensuring no fix is registered when the ClassCleanupBehavior compiler diagnostic occurs in a method body (non-attribute context).
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/RemoveClassCleanupBehaviorArgumentFixerTests.csAdds two new test methods covering the fixer’s “first argument” removal path and its “not inside attribute argument” no-op guard.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review June 25, 2026 05:26
@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 25, 2026
@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9410

ΔTestGradeBandNotes
newRemoveClassCleanupBehaviorArgumentFixerTests.
WhenClassCleanupBehaviorIsFirstArgument_
RemovesBehaviorKeepsInheritance
B80–89Correct assertion; body runs ~46 lines (inflated by required Roslyn code snippets) — mild length concern.
newRemoveClassCleanupBehaviorArgumentFixerTests.
WhenClassCleanupBehaviorReferencedOutsideAttribute_
NoFix
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. · 226.3 AIC · ⌖ 13.7 AIC · ⊞ 43.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.

✅ 10/10 applied dimensions clean — no findings.

Skipped (not applicable to a test-only diff): Threading & Concurrency, Security & IPC Contract Safety, Public API & Binary Compatibility, Performance & Allocations, Cross-TFM Compatibility, Resource & IDisposable Management, Defensive Coding at Boundaries, Localization & Resources, Analyzer & Code Fix Quality (src), IPC Wire Compatibility, Build Infrastructure & Dependencies, PowerShell Scripting Hygiene.

Applied dimensions:

#DimensionVerdict
1Algorithmic Correctness✅ LGTM
2Test Isolation✅ LGTM
3Assertion Quality✅ LGTM
4Flakiness Patterns✅ LGTM
5Test Completeness & Coverage✅ LGTM
6Data-Driven Test Coverage✅ LGTM
7Code Structure & Simplification✅ LGTM
8Naming & Conventions✅ LGTM
9Documentation Accuracy✅ LGTM
10Scope & PR Discipline✅ LGTM

Notes:

  • Algorithmic Correctness: Both diagnostic markers are correct. {|CS0103:ClassCleanupBehavior|} fires because the type is gone; {|CS1729:ClassCleanup(...)|} fires because no overload matches the erroneous first argument — exactly mirroring the second-argument pattern already exercised in WhenClassCleanupBehaviorArgument_Simple. The fixer's RemoveNode(attributeArgument, SyntaxRemoveOptions.KeepNoTrivia) on a SeparatedSyntaxList removes the first element and its following separator, producing (InheritanceBehavior.None) with no stray space — consistent with the expected fixedCode.

  • No-fix guard path:VerifyCodeFixAsync(code, code) is the correct idiom for asserting that no fix is registered. The guard in the fixer (attributeArgument is null → skip registration) is cleanly exercised by placing the CS0103 reference inside a method body statement, not inside any AttributeArgumentSyntax ancestor.

  • Inline comments: The // Exercises the branch... comments in the new test bodies are the only body-level comments in the file. They fall within the project's "comment what needs clarification" guideline and genuinely help readers understand which fixer branch is being targeted without requiring them to trace into the fixer implementation.

@Evangelink
Amaury Levé (Evangelink) merged commit 0575458 into mainJun 25, 2026
62 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/remove-classcleanuup-behavior-edge-cases-94eb5ef9f5cab19a branch June 25, 2026 06:18
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