Uh oh!
There was an error while loading. Please reload this page.
[test-improver] test: add edge case tests for UseCancellationTokenPropertyAnalyzer (MSTEST0054) - #9355
Conversation
…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>
There was a problem hiding this comment.
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.Tokenusage inside a[TestInitialize]method. - Added a negative test ensuring no diagnostic is produced for a non-
TestContexttype that happens to expose aCancellationTokenSourceproperty. - Added a diagnostic+code-fix test for
TestContextprovided as a method parameter (e.g.,[AssemblyInitialize]), validating the parameter-receiver pattern.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/UseCancellationTokenPropertyAnalyzerTests.cs | Adds 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
This comment has been minimized.
This comment has been minimized.
…-cases-9ce6120c1c396bcd
Amaury Levé (Evangelink)
commented
Jun 23, 2026
🧪 Test quality grade — PR #93553 new test methods graded in
This advisory comment was generated automatically. Grades are heuristic
|
Uh oh!
There was an error while loading. Please reload this page.
Goal and Rationale
UseCancellationTokenPropertyAnalyzer(MSTEST0054) had only 5 tests covering basic scenarios. Three meaningful boundary paths were untested:[TestInitialize]method (not just[TestMethod])CancellationTokenSourcepropertyTestContext.CancellationTokenSource, not any identically named propertyTestContextas a parameter (e.g.,AssemblyInitialize)Approach
Added three tests to
UseCancellationTokenPropertyAnalyzerTests, each following the existing pattern:WhenUsingCancellationTokenSourceInTestInitialize_ShouldReportDiagnostic—[TestInitialize]method accessingTestContext.CancellationTokenSource.Token; both the diagnostic and the→ CancellationTokenfix are verified.WhenCustomClassHasCancellationTokenSourceProperty_ShouldNotReportDiagnostic— a non-TestContext class with aCancellationTokenSourceproperty; no diagnostic expected, confirming the symbol equality check rejects non-TestContext types.WhenUsingCancellationTokenSourceOnParameterInAssemblyInitialize_ShouldReportDiagnostic—[AssemblyInitialize]method whereTestContextis a parameter (not a property); both the diagnostic and the fix are verified.Test Status
Build: ✅ succeeded
UseCancellationTokenPropertyAnalyzerTestsAll 8 tests pass.
Reproducibility
Add this agentic workflows to your repo
To install this agentic workflow, run