Skip to content

[test-improver] test: add edge case tests for UseCancellationTokenPropertyAnalyzer (MSTEST0054) - #9355

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/cancellation-token-property-edge-cases-9ce6120c1c396bcd
Jun 23, 2026
Merged

[test-improver] test: add edge case tests for UseCancellationTokenPropertyAnalyzer (MSTEST0054)#9355
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/cancellation-token-property-edge-cases-9ce6120c1c396bcd

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

UseCancellationTokenPropertyAnalyzer (MSTEST0054) had only 5 tests covering basic scenarios. Three meaningful boundary paths were untested:

Missing scenarioWhy it matters
[TestInitialize] method (not just [TestMethod])Verifies the analyzer fires on any method in a test class, not only test methods
Custom class with a CancellationTokenSource propertyVerifies the symbol comparison is exact — only TestContext.CancellationTokenSource, not any identically named property
TestContext as a parameter (e.g., AssemblyInitialize)Verifies the analyzer and fixer both handle the parameter-receiver pattern, not just the class-property pattern

Approach

Added three tests to UseCancellationTokenPropertyAnalyzerTests, each following the existing pattern:

  1. WhenUsingCancellationTokenSourceInTestInitialize_ShouldReportDiagnostic[TestInitialize] method accessing TestContext.CancellationTokenSource.Token; both the diagnostic and the → CancellationToken fix are verified.

  2. WhenCustomClassHasCancellationTokenSourceProperty_ShouldNotReportDiagnostic — a non-TestContext class with a CancellationTokenSource property; no diagnostic expected, confirming the symbol equality check rejects non-TestContext types.

  3. WhenUsingCancellationTokenSourceOnParameterInAssemblyInitialize_ShouldReportDiagnostic[AssemblyInitialize] method where TestContext is a parameter (not a property); both the diagnostic and the fix are verified.

Test Status

Build: ✅ succeeded

FileBeforeAfter
UseCancellationTokenPropertyAnalyzerTests58

All 8 tests pass.

Reproducibility

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

🤖 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.2K AIC · ⌖ 23.5 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

…STEST0054)
- WhenUsingCancellationTokenSourceInTestInitialize: verify the diagnostic
fires in [TestInitialize] methods, not just [TestMethod]
- WhenCustomClassHasCancellationTokenSourceProperty: verify the symbol
check is precise — a non-TestContext class with a property of the same
name does not trigger MSTEST0054
- WhenUsingCancellationTokenSourceOnParameterInAssemblyInitialize: verify
the analyzer and fixer both work when TestContext is passed as a
parameter (AssemblyInitialize pattern), not just as a class property
All 8 tests pass (5 existing + 3 new).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 22, 2026 23:39
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 22, 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

This PR strengthens coverage for the MSTest analyzer MSTEST0054 (UseCancellationTokenPropertyAnalyzer) by adding targeted unit tests for previously untested boundary scenarios, ensuring both the analyzer and code fixer behave correctly across additional MSTest method shapes.

Changes:

  • Added a diagnostic+code-fix test for CancellationTokenSource.Token usage inside a [TestInitialize] method.
  • Added a negative test ensuring no diagnostic is produced for a non-TestContext type that happens to expose a CancellationTokenSource property.
  • Added a diagnostic+code-fix test for TestContext provided as a method parameter (e.g., [AssemblyInitialize]), validating the parameter-receiver pattern.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/UseCancellationTokenPropertyAnalyzerTests.csAdds three new edge-case tests covering [TestInitialize], a non-TestContext lookalike property, and TestContext as a parameter in [AssemblyInitialize].

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 23, 2026 05:40
@Evangelink

This comment has been minimized.

@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 23, 2026
Amaury Levé (Evangelink) added a commit that referenced this pull request Jun 23, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9355

3 new test methods graded in UseCancellationTokenPropertyAnalyzerTests. All three follow the standard Roslyn analyzer test pattern for this repo: a descriptive When...Should... name, concise inline code/fixedCode fixtures, and a single meaningful VerifyCodeFixAsync or VerifyAnalyzerAsync assertion that validates both diagnostic detection and fix correctness. No issues found across the batch.

ΔTestGradeBandNotes
newUseCancellationTokenPropertyAnalyzerTests.
WhenCustomClassHasCancellationTokenSourceProperty_
ShouldNotReportDiagnostic
A90–100No issues found.
newUseCancellationTokenPropertyAnalyzerTests.
WhenUsingCancellationTokenSourceInTestInitialize_
ShouldReportDiagnostic
A90–100No issues found.
newUseCancellationTokenPropertyAnalyzerTests.
WhenUsingCancellationTokenSourceOnParameterInAssemblyInitialize_
ShouldReportDiagnostic
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. · 173.9 AIC · ⌖ 12.8 AIC · ⊞ 43.6K · [◷]( · )

@Evangelink
Amaury Levé (Evangelink) merged commit 9daf54d into mainJun 23, 2026
32 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/cancellation-token-property-edge-cases-9ce6120c1c396bcd branch June 23, 2026 13:56
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