百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

Meziantou.Xunit.ParallelTestFramework

> 编程语言
开源

并行运行 xUnit 测试用例

186 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

并行运行 xUnit 测试用例

[!IMPORTANT] xUnit.net v3 4.0.0 ships this functionality out of the box with the new ParallelMode.All parallel mode. If you target xUnit v3 4.0.0 or later, you no longer need this package — see MIGRATION.md for how to move to the built-in feature.

By default, xUnit runs all test cases in a test class synchronously. This package extends the default test framework to execute tests in parallel.

For xUnit v3:

bash
dotnet add package Meziantou.Xunit.v3.ParallelTestFramework

For xUnit v2:

bash
dotnet add package Meziantou.Xunit.ParallelTestFramework

By default, all tests will run in parallel. Selectively disable parallelization by adding the DisableParallelization attribute to a collection or theory.

…

`

Previous versions of this package relied on built in xUnit attributes instead of exposing a dedicated DisableParallelization attribute. For backwards compatibility, parallelization can also be disabled by adding an explicit Collection attribute or Theory attribute with DisableDiscoveryEnumeration enabled.

…

`

The code is greatly inspired by the sample from Travis Mortimer:

[!IMPORTANT] This package requires the preEnumerateTheories xUnit setting to be enabled (true). xUnit v3 will default this setting to false when using it with Microsoft Testing Platform (instead of VSTest). If this setting is not enabled, you may get unexpected results. To ensure the correct behavior, you must enable the preEnumerateTheories setting in your xunit.runner.json file:

json
{
  "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
  "preEnumerateTheories": true
}

Custom DataAttribute

When creating a custom DataAttribute, you must ensure that the SupportsDiscoveryEnumeration() method returns true for theory data rows to run in parallel. If this method returns false, the theory data rows will run sequentially.

csharp
public sealed class CustomDataAttribute : DataAttribute
{
    public override ValueTask> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)
    {
        var rows = new List
        {
            new TheoryDataRow(1),
            new TheoryDataRow(2),
            new TheoryDataRow(3),
        };
        return new ValueTask>(rows);
    }

    // Must return true for parallel execution of theory data rows
    public override bool SupportsDiscoveryEnumeration() => true;
}

Parallel in a collection

Using the EnableParallelizationAttribute on an ICollectionFixture enables the parallel execution between classes in a collection. If you want to enable parallisation inside a class you still need to add the EnableParallelizationAttribute on the test class aswell.

…

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言