Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Allow a trailing CancellationToken parameter on MSTest test methods

Open
#11,986 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Evangelink is already working on this.

Since Oct 16, 2026.

  • #11991 by @Evangelink — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
testing

Research direction

The proposal touches MSTest test discovery, execution (both reflection and source-generated paths), argument binding for DataRow and DynamicData, and the MSTest analyzers, so start by tracing how TestContext.CancellationToken is currently made available to a test body. Done means a test method with a trailing CancellationToken parameter receives the same token as TestContext, data-driven methods bind their data arguments unchanged, and invalid signatures are rejected consistently across discovery, execution and analyzers. The issue has no assignee or pull request yet, but the design spans several subsystems, so confirm the approach with maintainers before writing code.

Written by the indexing model from the issue text.

Description

area/mstest area/parameterized-tests needs/triage

Summary

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.

Proposed Feature

[TestMethod]
public async Task TestAsync(CancellationToken cancellationToken)
{
    await RunAsync(cancellationToken);
}

[TestMethod]
[DataRow(42)]
public async Task ParameterizedTestAsync(int value, CancellationToken cancellationToken)
{
    await RunAsync(value, cancellationToken);
}
  • 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.

Dominant language
C#
Stars
1k
Forks
314
Avg merge
9h 33m
Merged PRs (30d)
427

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/testfx

All issues in microsoft/testfx

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.