[test-improver] test: add edge case tests for UnusedParameterSuppressor (MSTEST0047)#9301
Conversation
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>
There was a problem hiding this comment.
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 TestContext and the containing method is one of the supported fixture lifecycle methods.
Changes:
- Added a negative test verifying
[TestMethod]+ unusedTestContextis not suppressed. - Added a negative test verifying
[AssemblyInitialize]+ unused non-TestContextparameter is not suppressed.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/UnusedParameterSuppressorTests.cs | Adds 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
🧪 Test quality grade — PR #9301
This advisory comment was generated automatically. Grades are heuristic
|
Evangelink
left a comment
There was a problem hiding this comment.
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 beTestContext, and (2) the containing method must carry one of the four fixture attributes.TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressedexercises condition-1-true / condition-2-false;AssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressedexercises 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 theAssemblyInitialize/ClassInitializeestablished 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
Assertfamily is the correct choice for this project perBannedSymbols.txt).
Goal and Rationale
UnusedParameterSuppressor(MSTEST0047) suppresses IDE0060 ("Remove unused parameter") when both of these hold:TestContext[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:TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressed[TestMethod]with unusedTestContextparameter[TestMethod]is not in the fixture-attribute listAssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressed[AssemblyInitialize]with unusedstringparameterTestContextparameters are eligibleEach 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
Test Status
Build: ✅ succeeded (0 warnings, 0 errors)
MSTest.Analyzers.UnitTests(UnusedParameterSuppressorTests): ✅ 8 passed, 0 failed (was 6)Add this agentic workflows to your repo
To install this agentic workflow, run