Allow a trailing CancellationToken parameter on MSTest test methods

クローズ
#11,986 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Evangelink がすでに取り組んでいます。

2026年10月16日 から。

  • #11991 @Evangelink による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
22/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C#
スター
1.1k
フォーク
312
平均マージ
11時間 6分
マージ済み PR(30日)
326

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/testfx のほかの issue

microsoft/testfx の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。