Nullean.Xunit.Partitions 0.14.1

dotnet add package Nullean.Xunit.Partitions --version 0.14.1
                    
NuGet\Install-Package Nullean.Xunit.Partitions -Version 0.14.1
                    
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="Nullean.Xunit.Partitions" Version="0.14.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nullean.Xunit.Partitions" Version="0.14.1" />
                    
Directory.Packages.props
<PackageReference Include="Nullean.Xunit.Partitions" />
                    
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 Nullean.Xunit.Partitions --version 0.14.1
                    
#r "nuget: Nullean.Xunit.Partitions, 0.14.1"
                    
#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 Nullean.Xunit.Partitions@0.14.1
                    
#: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=Nullean.Xunit.Partitions&version=0.14.1
                    
Install as a Cake Addin
#tool nuget:?package=Nullean.Xunit.Partitions&version=0.14.1
                    
Install as a Cake Tool

Nullean.Xunit.Partitions

nullean

Partitions for xUnit v2: share a few expensive, long-lived objects across thousands of tests, set up just before the tests that need them and torn down right after, one partition at a time. For xUnit v3, use Nullean.Xunit.Partitions.v3.

NuGet

Install

dotnet add package Nullean.Xunit.Partitions

Quick start

Register the partition test framework with an assembly-level attribute, anywhere in the test project:

using Nullean.Xunit.Partitions;
using Xunit;

[assembly: TestFramework(Partition.TestFramework, Partition.Assembly)]

Give the shared state an IPartitionLifetime, and let test classes ask for it with IPartitionFixture<T>:

using AwesomeAssertions;
using Nullean.Xunit.Partitions.Sdk;
using Xunit;

// The shared state: initialised just before its partition's tests run, disposed right after.
public class Database : IPartitionLifetime
{
	private static int _starts;
	public int Starts => _starts;

	public Task InitializeAsync()
	{
		Interlocked.Increment(ref _starts);   // start a container, a server, a browser...
		return Task.CompletedTask;
	}

	public Task DisposeAsync() => Task.CompletedTask;

	public int? MaxConcurrency => null;        // test classes run at once; null for the default
	public string FailureTestOutput() => "";   // reported on every test of the partition if InitializeAsync throws
}

public class OrderTests(Database db) : IPartitionFixture<Database>
{
	[Fact]
	public void StartedOnce() => db.Starts.Should().Be(1);
}

public class CustomerTests(Database db) : IPartitionFixture<Database>
{
	[Fact]
	public void SharesTheInstance() => db.Starts.Should().Be(1);
}

OrderTests and CustomerTests receive one shared Database, after its InitializeAsync has run. xUnit's analyzer reports partition fixtures as xUnit1041; add <NoWarn>$(NoWarn);xUnit1041</NoWarn> to the test project. PartitionContext.TestException holds the exception of the running test, if any.

How it runs

  • One partition at a time. No partition runs concurrently with another, by design, so each partition's state can run expensive operations (start Docker containers or processes, bootstrap Playwright) in isolation.
  • Concurrent inside a partition. Unlike xUnit's ICollectionFixture<T>, a partition is not a concurrency barrier: the test classes that share a partition run concurrently.
  • Just in time. InitializeAsync runs right before a partition's tests and DisposeAsync right after, before the next partition initialises. Assembly fixtures bootstrap too early and dispose too late.
  • No partition is a partition too. Test classes without IPartitionFixture<T> run together, concurrently, as one more partition.
  • If InitializeAsync throws, every test of the partition fails with the exception and the text of FailureTestOutput(), such as a server's log.
  • MaxConcurrency is how many of the partition's test classes run at once. The runner uses the larger of it and its default, 4 x the processor count, so only a higher value changes anything; null keeps the default.

If you want to share a few (say 0 to 20) long-running objects over thousands of tests, this library will work for you. If you instead have many test collections each with only a few tests, xUnit's own collections suit better.

Providing options

Filter which partitions and test classes run with an options class; filtered-out tests are reported as skipped. OnBeforeTestsRun() and OnTestsFinished(...) can be overridden for logging or reporting.

using Nullean.Xunit.Partitions;

[assembly: PartitionOptions(typeof(MyPartitioningOptions))]

public class MyPartitioningOptions : PartitionOptions
{
	public MyPartitioningOptions()
	{
		PartitionFilterRegex = "Database";   // only run partitions whose lifetime type name matches
		TestFilterRegex = null;              // only run test classes whose name matches (null = all)
	}
}

Learn more

Product 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 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. 
.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 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  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.
  • .NETFramework 4.6.2

  • .NETStandard 2.0

  • .NETStandard 2.1

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Nullean.Xunit.Partitions:

Package Downloads
Elastic.Elasticsearch.Xunit

Provides an Xunit test framework allowing you to run integration tests against local ephemeral Elasticsearch clusters

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.14.1 93 11/12/2026
0.13.0 95 11/11/2026
0.12.0 252 2/17/2026
0.11.0 7,281 2/16/2026
0.10.0 14,417 11/12/2025
0.5.0 16,122 2/22/2024
0.4.3 437 2/13/2024
0.4.2 264 2/9/2024
0.4.1 243 2/9/2024
0.4.0 256 2/9/2024
0.3.0 284 2/9/2024