Meziantou.Xunit.v3.ParallelTestFramework
1.0.6
Prefix Reserved
dotnet add package Meziantou.Xunit.v3.ParallelTestFramework --version 1.0.6
NuGet\Install-Package Meziantou.Xunit.v3.ParallelTestFramework -Version 1.0.6
<PackageReference Include="Meziantou.Xunit.v3.ParallelTestFramework" Version="1.0.6" />
<PackageVersion Include="Meziantou.Xunit.v3.ParallelTestFramework" Version="1.0.6" />
<PackageReference Include="Meziantou.Xunit.v3.ParallelTestFramework" />
paket add Meziantou.Xunit.v3.ParallelTestFramework --version 1.0.6
#r "nuget: Meziantou.Xunit.v3.ParallelTestFramework, 1.0.6"
#:package Meziantou.Xunit.v3.ParallelTestFramework@1.0.6
#addin nuget:?package=Meziantou.Xunit.v3.ParallelTestFramework&version=1.0.6
#tool nuget:?package=Meziantou.Xunit.v3.ParallelTestFramework&version=1.0.6
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:
dotnet add package Meziantou.Xunit.v3.ParallelTestFramework
For xUnit v2:
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
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:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"preEnumerateTheories": true
}
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 is compatible. 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. |
| .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. |
-
.NETStandard 2.0
- xunit.v3.extensibility.core (>= 3.0.0)
-
net9.0
- xunit.v3.extensibility.core (>= 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.