[test-improver] test: add edge case tests for UnusedParameterSuppressor (MSTEST0047)#9301
Draft
Evangelink wants to merge 1 commit into
Draft
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>
Contributor
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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