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:

Test What 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>
Copilot AI review requested due to automatic review settings June 24, 2026 23:44
@Evangelink Amaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 24, 2026

Copilot AI 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
File Description
test/UnitTests/MSTest.Analyzers.UnitTests/RemoveClassCleanupBehaviorArgumentFixerTests.cs Adds 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
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) June 25, 2026 05:26
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 25, 2026
@Evangelink

Copy link
Copy Markdown
Member Author

🧪 Test quality grade — PR #9410

ΔTestGradeBandNotes
new RemoveClassCleanupBehaviorArgumentFixerTests.
WhenClassCleanupBehaviorIsFirstArgument_
RemovesBehaviorKeepsInheritance
B 80–89 Correct assertion; body runs ~46 lines (inflated by required Roslyn code snippets) — mild length concern.
new RemoveClassCleanupBehaviorArgumentFixerTests.
WhenClassCleanupBehaviorReferencedOutsideAttribute_
NoFix
A 90–100 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. 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 · [◷]( · )

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member Author

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:

# Dimension Verdict
1 Algorithmic Correctness ✅ LGTM
2 Test Isolation ✅ LGTM
3 Assertion Quality ✅ LGTM
4 Flakiness Patterns ✅ LGTM
5 Test Completeness & Coverage ✅ LGTM
6 Data-Driven Test Coverage ✅ LGTM
7 Code Structure & Simplification ✅ LGTM
8 Naming & Conventions ✅ LGTM
9 Documentation Accuracy ✅ LGTM
10 Scope & 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 main Jun 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 free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team. type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants