TUnit 0.1.366-alpha01

Prefix Reserved
This is a prerelease version of TUnit.
There is a newer version of this package available.
See the version list below for details.
dotnet add package TUnit --version 0.1.366-alpha01
                    
NuGet\Install-Package TUnit -Version 0.1.366-alpha01
                    
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="TUnit" Version="0.1.366-alpha01" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TUnit" Version="0.1.366-alpha01" />
                    
Directory.Packages.props
<PackageReference Include="TUnit" />
                    
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 TUnit --version 0.1.366-alpha01
                    
#r "nuget: TUnit, 0.1.366-alpha01"
                    
#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 TUnit@0.1.366-alpha01
                    
#: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=TUnit&version=0.1.366-alpha01&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TUnit&version=0.1.366-alpha01&prerelease
                    
Install as a Cake Tool

TUnit

T(est)Unit!

Documentation

See here: https://thomhurst.github.io/TUnit/

Features

  • Source generated tests
  • Full async support
  • Easy to read assertions
  • Flexible test data mechanisms
  • Flexible setup and cleanup mechanisms
  • Out of the box concurrency
  • Designed to avoid common pitfalls (leaky test states, shared instances, etc.)
  • Global test hooks
  • Test context interrogation providing test details and test state

Installation

dotnet add package TUnit --prerelease

Example test

    [Test]
    public async Task Test1()
    {
        var value = "Hello world!";
        
        await Assert.That(value)
            .Is.Not.Null
            .And.Does.StartWith("H")
            .And.Has.Count().EqualTo(12)
            .And.Is.EqualTo("hello world!", StringComparison.InvariantCultureIgnoreCase);
    }

Motivations

There are only three main testing frameworks in the .NET world - xUnit, NUnit and MSTest. More frameworks means more options, and more options motivates more features or improvements.

These testing frameworks are amazing, but I've had some issues with them. You might not have had any of these, but these are my experiences:

xUnit

There is no way to tap into information about a test in a generic way. For example, I've had some Playwright tests run before, and I want them to save a screenshot or video ONLY when the test fails. If the test passes, I don't have anything to investigate, and it'll use up unnecessary storage, and it'll probably slow my test suite down if I had hundreds or thousands of tests all trying to save screenshots.

However, if I'm in a Dispose method which is called when the test ends, then there's no way for me to know if my test succeeded or failed. I'd have to do some really clunky workaround involving try catch and setting a boolean or exception to a class field and checking that. And to do that for every test was just not ideal.

Assertions

I have stumbled across assertions so many times where the arguments are the wrong way round. This can result in really confusing error messages.

var one = 2;
Assert.Equal(1, one)
Assert.Equal(one, 1)

NUnit

Assertions

I absolutely love the newer assertion syntax in NUnit. The Assert.That(something, Is.Something). I think it's really clear to read, it's clear what is being asserted, and it's clear what you're trying to achieve.

However, there is a lack of type checking on assertions. (Yes, there are analyzer packages to help with this, but this still isn't strict type checking.)

Assert.That("1", Throws.Exception);

This assertion makes no sense, because we're passing in a string. This can never throw an exception because it isn't a delegate that can be executed. But it's still perfectly valid code that will compile.

As does this: Assert.That(1, Does.Contain("Foo!"));

An integer can not contain a string. Of course these will fail at runtime, but we could move these errors up to compile time for faster feedback. This is very useful for long pipelines or build times.

Some methods also just read a little bit weird: Assert.That(() => Something(), Throws.Exception.Message.Contain(someMessage));

"Throws Exception Message Contain someMessage" - It's not terrible, but it could read a little better.

With TUnit assertions, I wanted to make these impossible to compile. So type constraints are built into the assertions themselves. There should be no way for a non-delegate to be able to do a Throws assertion, or for an int assertion to check for string conditions.

So in TUnit, this will compile:

await Assert.That(() => GetSomeValue()).Throws.Nothing;

This won't:

await Assert.That(GetSomeValue()).Throws.Nothing;
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on TUnit:

Package Downloads
TUnit.Playwright

A .NET Testing Framework

Saucery.TUnit

Sorcery for SauceLabs - Unlocking SauceLabs capability

Rewrite.Test

Test harness for the automated code refactoring framework OpenRewrite.

rbkApiModules.Testing.Core

Package Description

CookieCrumble.TUnit

Package Description

GitHub repositories (29)

Showing the top 20 popular GitHub repositories that depend on TUnit:

Repository Stars
MaterialDesignInXAML/MaterialDesignInXamlToolkit
Google's Material Design in XAML & WPF, for C# & VB.Net.
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
fluentassertions/fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
VerifyTests/Verify
Verify is a snapshot testing tool that simplifies the assertion of complex data models and documents.
Nexus-Mods/NexusMods.App
Home of the development of the Nexus Mods App
wiremock/WireMock.Net
WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on WireMock Java, but extended with more functionality.Full documentation can be found at https://wiremock.org/dotnet/.
TNG/ArchUnitNET
A C# architecture test library to specify and assert architecture rules in C# for automated testing.
AwesomeAssertions/AwesomeAssertions
A fork of FluentAssertions controlled by the community.
andrewlock/NetEscapades.AspNetCore.SecurityHeaders
Small package to allow adding security headers to ASP.NET Core websites
erwinkramer/bank-api
The Bank API is a design reference project suitable to bootstrap development for a compliant and modern API.
JasperFx/alba
Easy integration testing for ASP.NET Core applications
Eventuous/eventuous
Event Sourcing library for .NET
thomhurst/ModularPipelines
Write your pipelines in C# !
foxminchan/BookWorm
The practical implementation of Aspire using Microservices, AI-Agents
LightBDD/LightBDD
BDD framework allowing to create easy to read and maintain tests.
SwissLife-OSS/snapshooter
Snapshooter is a snapshot testing tool for .NET Core and .NET Framework
eiriktsarpalis/PolyType
Practical generic programming for .NET
Lyrcaxis/KokoroSharp
Fast local TTS inference engine in C# with ONNX runtime. Multi-speaker, multi-platform and multilingual. Integrate on your .NET projects using a plug-and-play NuGet package, complete with all voices.
DamianMorozov/OpenTgResearcher
OpenTgResearcher - tool for analyzing Telegram chats and downloading their content
thomhurst/EnumerableAsyncProcessor
Process Multiple Asynchronous Tasks in Various Ways - One at a time / Batched / Rate limited / Concurrently
Version Downloads Last Updated
1.15.0 6 2/15/2026
1.14.0 1,626 2/14/2026
1.13.70 348 2/14/2026
1.13.69 150 2/14/2026
1.13.60 2,291 2/13/2026
1.13.56 1,588 2/12/2026
1.13.54 406 2/12/2026
1.13.51 1,297 2/12/2026
1.13.48 670 2/12/2026
1.13.47 385 2/11/2026
1.13.40 3,569 2/10/2026
1.13.30 856 2/10/2026
1.13.27 954 2/10/2026
1.13.24 616 2/10/2026
1.13.11 8,136 2/7/2026
1.13.8 711 2/6/2026
1.13.0 2,297 2/6/2026
1.12.147 2,330 2/6/2026
1.12.144 1,596 2/5/2026
0.1.366-alpha01 135 6/21/2024
Loading failed