Skip to content

[test-improver] test: add edge case tests for UnusedParameterSuppressor (MSTEST0047) - #9301

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
test-assist/unused-parameter-suppressor-edge-cases-ac3065608b409b3d
Jun 21, 2026
Merged

[test-improver] test: add edge case tests for UnusedParameterSuppressor (MSTEST0047)#9301
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
test-assist/unused-parameter-suppressor-edge-cases-ac3065608b409b3d

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

UnusedParameterSuppressor (MSTEST0047) suppresses IDE0060 ("Remove unused parameter") when both of these hold:

  1. The parameter type is TestContext
  2. The containing method has [AssemblyInitialize], [ClassInitialize], [GlobalTestInitialize], or [GlobalTestCleanup]

The existing tests verified the positive cases (suppressed) and two negative cases (regular method / non-TestContext in TestMethod). However, the exact boundary conditions — one condition true but not the other — were untested.

Approach

Added two new test methods to UnusedParameterSuppressorTests.cs:

TestScenarioExpected
TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressed[TestMethod] with unused TestContext parameterNot suppressed[TestMethod] is not in the fixture-attribute list
AssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressed[AssemblyInitialize] with unused string parameterNot suppressed — only TestContext parameters are eligible

Each test runs twice: once without the suppressor (to confirm the diagnostic fires), and once with the suppressor (to confirm it is not suppressed).

Coverage Impact

These tests target the two independent guard conditions in UnusedParameterSuppressor.ReportSuppressions, ensuring the parameter-type check and the attribute check are each independently exercised with a failing case.

Trade-offs

Minimal — tests follow the existing pattern in the file and add no complexity.

Reproducibility

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

Test Status

Build: ✅ succeeded (0 warnings, 0 errors)
MSTest.Analyzers.UnitTests (UnusedParameterSuppressorTests): ✅ 8 passed, 0 failed (was 6)

🤖 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. · 1.7K AIC · ⌖ 23.7 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

Add two missing edge case tests to verify the suppressor's exact boundaries:
1. TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressed: verifies that
a TestContext parameter in a [TestMethod] (not a fixture attribute) is NOT
suppressed — [TestMethod] is absent from the suppressor's allowed-attribute
list.
2. AssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressed:
verifies that a non-TestContext parameter (e.g. string) inside
[AssemblyInitialize] is NOT suppressed — only TestContext parameters qualify.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 20, 2026 23:36
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 20, 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 boundary-condition coverage for the UnusedParameterSuppressor (MSTEST0047) tests in the MSTest analyzers unit test suite, ensuring the suppressor only applies when both the parameter is TestContextand the containing method is one of the supported fixture lifecycle methods.

Changes:

  • Added a negative test verifying [TestMethod] + unused TestContext is not suppressed.
  • Added a negative test verifying [AssemblyInitialize] + unused non-TestContext parameter is not suppressed.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/UnusedParameterSuppressorTests.csAdds two edge-case tests to independently exercise the suppressor’s attribute guard and parameter-type 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 21, 2026 07:21
@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9301

ΔTestGradeBandNotes
newUnusedParameterSuppressorTests.
AssemblyInitializeWithUnusedNonTestContextParameter_
DiagnosticIsNotSuppressed
B80–89Strong diagnostic assertions (WithLocation, WithArguments, WithIsSuppressed); body is slightly long (~44 lines) due to embedded code string and idiomatic dual-run pattern.
newUnusedParameterSuppressorTests.
TestMethodWithUnusedTestContext_
DiagnosticIsNotSuppressed
B80–89Precise assertions verify diagnostic presence, location, argument name, and suppression state; mildly long (~44 lines) due to multi-line string literal and dual suppressor/non-suppressor verification runs.

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. · 183.3 AIC · ⌖ 13 AIC · ⊞ 43.6K · [◷]( · )

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.


Scope: single test file (test/UnitTests/MSTest.Analyzers.UnitTests/UnusedParameterSuppressorTests.cs); no production code changed.

Reviewed dimensions: Algorithmic Correctness · Threading & Concurrency · Security · Public API Compatibility · Performance · Cross-TFM · Resource Management · Defensive Coding · Localization · Test Isolation · Assertion Quality · Flakiness · Test Completeness · Data-Driven Coverage · Code Structure · Naming · Documentation · Analyzer Quality · IPC Wire · Build Infrastructure · Scope Discipline · PowerShell Hygiene

Notes:

  • Both new tests correctly model the two independent guard conditions of UnusedParameterSuppressor: (1) the parameter type must be TestContext, and (2) the containing method must carry one of the four fixture attributes. TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressed exercises condition-1-true / condition-2-false; AssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressed exercises condition-1-false / condition-2-true. Both complement the four existing positive tests and the two pre-existing negative tests without any overlap.
  • Each test correctly runs two phases — without the suppressor (baseline) and with the suppressor — and asserts WithIsSuppressed(false) in both, consistent with the AssemblyInitialize/ClassInitialize established pattern in the file.
  • Test names follow the <Scenario>_<Expected> convention used throughout the file. Comments explain why the diagnostic is not suppressed, not just what the test does — good practice.
  • No shared mutable state, no timing dependencies, no file-system access, no assertion library violations (MSTest Assert family is the correct choice for this project per BannedSymbols.txt).

@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 21, 2026

@0101Petr Pokorny (0101) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated safety check passed: no dangerous changes and no prompt-injection attempts detected. Approving as requested. Note: this is a quick safety sanity check, not a full code review.

@Evangelink
Amaury Levé (Evangelink) merged commit 10f38cb into mainJun 21, 2026
56 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/unused-parameter-suppressor-edge-cases-ac3065608b409b3d branch June 21, 2026 13:54
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