Tennisi.Xunit.v2.ParallelTestFramework 1.0.427

dotnet add package Tennisi.Xunit.v2.ParallelTestFramework --version 1.0.427
                    
NuGet\Install-Package Tennisi.Xunit.v2.ParallelTestFramework -Version 1.0.427
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tennisi.Xunit.v2.ParallelTestFramework" Version="1.0.427" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tennisi.Xunit.v2.ParallelTestFramework" Version="1.0.427" />
                    
Directory.Packages.props
<PackageReference Include="Tennisi.Xunit.v2.ParallelTestFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tennisi.Xunit.v2.ParallelTestFramework --version 1.0.427
                    
#r "nuget: Tennisi.Xunit.v2.ParallelTestFramework, 1.0.427"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tennisi.Xunit.v2.ParallelTestFramework@1.0.427
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tennisi.Xunit.v2.ParallelTestFramework&version=1.0.427
                    
Install as a Cake Addin
#tool nuget:?package=Tennisi.Xunit.v2.ParallelTestFramework&version=1.0.427
                    
Install as a Cake Tool

Tennisi.Xunit assembly

Tennisi.Xunit namespace

public type description
struct ParallelTag A readonly structure that serves as a Xunit fixture to provide unique but constant value for test fact or theory version, facilitating parallel execution of tests while ensuring consistency in tagging.
class TestParallelizationAttribute An attribute that controls test parallelization and the maximum number of test tasks running in parallel in the xUnit framework. Can be applied at the assembly, test class, or test method level.

Tennisi.Xunit.v2.ParallelTestFramework assembly

Tennisi.Xunit namespace

public type description
class RetryClassAttribute Represents a custom xUnit attribute to specify that all test methods in the class (both facts and theories) should be retried a specified number of times.
class RetryFactAttribute Represents a custom xUnit attribute to retry a test a specified number of times.
class RetryTheoryAttribute Represents a custom xUnit attribute to retry a theory test a specified number of times.

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

dotnet add package Tennisi.Xunit.ParallelTestFramework

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

// All tests are run in parallel
public class ParallelTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);

    [Theory]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test3(int value) => Thread.Sleep(2000);

    // This test runs in parallel with other tests
    // However, its test cases are run sequentially
    [Theory]
    [DisableParallelization]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test4(int value) => Thread.Sleep(2000);
}

// This collection runs in parallel with other collections
// However, its tests cases are run sequentially
[DisableParallelization]
public class SequentialTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);
}

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.

// All tests are run in parallel
public class ParallelTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);

    [Theory]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test3(int value) => Thread.Sleep(2000);

    // This test runs in parallel with other tests
    // However, its test cases are run sequentially because of DisableDiscoveryEnumeration
    [Theory]
    [MemberData(nameof(GetData), DisableDiscoveryEnumeration = true)]
    public void Test4(int value) => Thread.Sleep(2000);

    public static TheoryData<int> GetData() =>  new() { { 0 }, { 1 } };
}

// This collection runs in parallel with other collections
// However, its tests cases are run sequentially because the Collection is explicit
[Collection("Sequential")]
public class SequentialTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);
}

The code is greatly inspired by the sample from Travis Mortimer: https://github.com/xunit/xunit/issues/1986#issuecomment-831322722

Parallel in a collection

Using the EnableParallelizationAttribute on an ICollectionFixture<T> 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.

[CollectionDefinition("MyFixture Collection")]
[EnableParallelization] // This enables the parallel execution of classes in a collection 
public class MyFixtureCollection : ICollectionFixture<MyFixture>
{
}

[Collection("MyFixture Collection")]
public class MyFirstTestClass
{
    private readonly MyFixture fixture;

    public ParallelCollectionMultiClass1AttributeTests(MyFixture fixture)
    {
        this.fixture = fixture;
    }

    //...
}

[Collection("MyFixture Collection")]
public class MySecondTestClass
{
    private readonly MyFixture fixture;

    public ParallelCollectionMultiClass1AttributeTests(MyFixture fixture)
    {
        this.fixture = fixture;
    }

    //...
}

Achieving Maximum Productivity

Use the FullTestParallelizationAttribute on an assembly and inject ParallelTag into the constructor of each of your tests.

public class MyTests
{
    private readonly int _betId;
    
    public MyTests(ITestOutputHelper helper, ParallelTag tag = new())
    {
        _betId = tag.AsLong();
    }
    
    [Fact]
    public void Do()
    {
       
    }   
}

This strategy will allow you to run each Fact or Theory variant in parallel. Each time xUnit starts your test, a new unique but constant ParallelTag will be injected into your test class, allowing your test to work with unique data without interfering with other tests.

WinForms/WPF Applications

STA model apps should use the Tennisi.Xunit.ParallelTestFramework.UI package.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.427 217 4/6/2025
1.0.426 195 4/6/2025
1.0.401 152 4/5/2025
1.0.313 538 3/13/2025
1.0.311 201 3/13/2025
1.0.310 213 3/13/2025
1.0.305 232 3/12/2025
1.0.304 189 2/14/2025
1.0.3 180 2/13/2025
1.0.2 168 2/5/2025
1.0.1 177 2/3/2025
1.0.0-preview.64 109 2/3/2025
1.0.0-preview.60 115 2/2/2025
1.0.0-preview.59 119 2/2/2025
1.0.0-preview.58 101 2/1/2025
1.0.0-preview.57 109 1/31/2025
1.0.0-preview.56 106 1/31/2025
1.0.0-preview.55 105 1/31/2025
1.0.0-preview.0 112 1/31/2025
0.0.0-alpha.0 100 2/3/2025
Loading failed