Meziantou.Xunit.ParallelTestFramework 2.3.0

Prefix Reserved
dotnet add package Meziantou.Xunit.ParallelTestFramework --version 2.3.0                
NuGet\Install-Package Meziantou.Xunit.ParallelTestFramework -Version 2.3.0                
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="Meziantou.Xunit.ParallelTestFramework" Version="2.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Meziantou.Xunit.ParallelTestFramework --version 2.3.0                
#r "nuget: Meziantou.Xunit.ParallelTestFramework, 2.3.0"                
#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.
// Install Meziantou.Xunit.ParallelTestFramework as a Cake Addin
#addin nuget:?package=Meziantou.Xunit.ParallelTestFramework&version=2.3.0

// Install Meziantou.Xunit.ParallelTestFramework as a Cake Tool
#tool nuget:?package=Meziantou.Xunit.ParallelTestFramework&version=2.3.0                

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 Meziantou.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;
    }

    //...
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Meziantou.Xunit.ParallelTestFramework:

Package Downloads
FunFair.Test.Common

FunFair Common Test Infrastructure for building xUnit tests on top of.

BunsenBurner.Xunit

Integration with [xUnit.net](https://github.com/xunit/xunit) to easily consume Bunsen Burner

Saucery.XUnit

Sorcery for SauceLabs - Unlocking SauceLabs capability

GitHub repositories (7)

Showing the top 5 popular GitHub repositories that depend on Meziantou.Xunit.ParallelTestFramework:

Repository Stars
riok/mapperly
A .NET source generator for generating object mappings. No runtime reflection.
alirezanet/Husky.Net
Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
ForNeVeR/Cesium
C compiler for the CLI platform
platformplatform/PlatformPlatform
Alpha state. A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
AnthonyLloyd/CsCheck
Random testing library for C#
Version Downloads Last updated
2.3.0 118,465 7/31/2024
2.2.0 89,167 5/29/2024
2.1.0 585,111 11/10/2022
2.0.0 5,705 10/5/2022
1.0.0 127,326 1/25/2022