You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow a trailing CancellationToken parameter on MSTest test methods #11986
Allow MSTest test methods to declare one additional trailing CancellationToken parameter. MSTest supplies TestContext.CancellationToken automatically, so a non-parameterized test can take one parameter and a parameterized test with X data arguments can take X + 1 parameters.
Background and Motivation
Tests currently need access to TestContext just to forward its cancellation token to asynchronous operations. A method parameter makes cooperative cancellation explicit and avoids that boilerplate.
Inject the exact current TestContext.CancellationToken, preserving its existing cancellation and timeout lifetime.
Support ordinary methods and data-driven methods, including DataRow and DynamicData.
Keep discovery, reflection/source-generated execution, argument validation, and MSTest analyzers consistent.
Preserve existing test signatures and data binding; do not inject arbitrary parameters or change lifecycle method signatures.
Add regression coverage for token identity, cancellation, data arguments, invalid signatures, and existing behavior.
Alternative Designs
Continue using TestContext.CancellationToken inside the test body. No new attribute or general dependency-injection mechanism is needed for the proposed convenience.
Activity