TUnit 0.1.653

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

TUnit

A modern, flexible and fast testing framework for .NET 8 and up. With Native AOT and Single File application support included!

Documentation

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

IDE

TUnit is built on top of the newer Microsoft.Testing.Platform, as opposed to the older VSTest platform. As of September 2024, IDEs do not fully support this testing platform yet.

Visual Studio 17.10 onwards can run the new tests by enabling the new testing platform server mode, within Visual Studio preview/experimental features. You will have to opt in to this manually.

For Rider, it is not yet supported. I believe they are working on it so we just have to wait for now.

dotnet CLI - Fully supported. Tests should be runnable with dotnet test or dotnet run, dotnet exec or executing an executable directly. See the docs for more information!

Features

  • Native AOT + Single File application support
  • Source generated tests
  • Full async support
  • Parallel by default, with mechanisms to:
    • Run specific tests completely on their own
    • Run specific tests not in parallel with other specific tests
    • Limit the a parallel limit on a per-test, class or assembly level
  • Test ordering (if running not in parallel)
  • Tests can depend on other tests to form chains, useful for if one test depends on state from another action
  • Easy to read assertions
  • Injectable test data via classes, methods, compile-time args, or matrices
  • Hooks before and after:
    • TestDiscover
    • TestSession
    • Assembly
    • Class
    • Test
  • Designed to avoid common pitfalls such as leaky test states
  • Ability to view and interrogate metadata and results from various assembly/class/test context objects

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);
    }

or with more complex test orchestration needs

    [Before(Class)]
    public static async Task ClearDatabase(ClassHookContext context) { ... }

    [After(Class)]
    public static async Task AssertDatabaseIsAsExpected(ClassHookContext context) { ... }

    [Before(Test)]
    public async Task CreatePlaywrightBrowser(TestContext context) { ... }

    [After(Test)]
    public async Task DisposePlaywrightBrowser(TestContext context) { ... }

    [Retry(3)]
    [Test, DisplayName("Register an account")]
    [EnumerableMethodData(nameof(GetAuthDetails))]
    public async Task Register(string username, string password) { ... }

    [Repeat(5)]
    [Test, DependsOn(nameof(Register))]
    [EnumerableMethodData(nameof(GetAuthDetails))]
    public async Task Login(string username, string password) { ... }

    [Test, DependsOn(nameof(Login), [typeof(string), typeof(string)])]
    [EnumerableMethodData(nameof(GetAuthDetails))]
    public async Task DeleteAccount(string username, string password) { ... }

    [Category("Downloads")]
    [Timeout(300_000)]
    [Test, NotInParallel(Order = 1)]
    public async Task DownloadFile1() { ... }

    [Category("Downloads")]
    [Timeout(300_000)]
    [Test, NotInParallel(Order = 2)]
    public async Task DownloadFile2() { ... }

    [Repeat(10)]
    [Test]
    [Arguments(1)]
    [Arguments(2)]
    [Arguments(3)]
    [DisplayName("Go to the page numbered $page")]
    public async Task GoToPage(int page) { ... }

    [Category("Cookies")]
    [Test, Skip("Not yet built!")]
    public async Task CheckCookies() { ... }

    [Test, Explicit, WindowsOnlyTest, RetryHttpServiceUnavailable(5)]
    [Property("Some Key", "Some Value")]
    public async Task Ping() { ... }

    [Test]
    [ParallelLimit<LoadTestParallelLimit>]
    [Repeat(1000)]
    public async Task LoadHomepage() { ... }

    public static IEnumerable<(string Username, string Password)> GetAuthDetails()
    {
        yield return ("user1", "password1");
        yield return ("user2", "password2");
        yield return ("user3", "password3");
    }

    public class WindowsOnlyTestAttribute : SkipAttribute
    {
        public WindowsOnlyTestAttribute() : base("Windows only test")
        {
        }

        public override Task<bool> ShouldSkip(TestContext testContext)
        {
            return Task.FromResult(!OperatingSystem.IsWindows());
        }
    }

    public class RetryHttpServiceUnavailableAttribute : RetryAttribute
    {
        public RetryHttpServiceUnavailableAttribute(int times) : base(times)
        {
        }

        public override Task<bool> ShouldRetry(TestInformation testInformation, Exception exception, int currentRetryCount)
        {
            return Task.FromResult(exception is HttpRequestException { StatusCode: HttpStatusCode.ServiceUnavailable });
        }
    }

    public class LoadTestParallelLimit : IParallelLimit
    {
        public int Limit => 50;
    }

Motivations

TUnit is inspired by NUnit and xUnit - two of the most popular testing frameworks for .NET.

It aims to build upon the useful features of both while trying to address any pain points that they may have. You may have experienced these, or you may have not even known about them.

Read more here

Benchmark

Scenario: A single test that completes instantly (including spawning a new process and initialising the test framework)

macos-latest

BenchmarkDotNet v0.14.0, macOS Sonoma 14.6.1 (23G93) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD


Method Mean Error StdDev
TUnit_AOT 81.40 ms 0.565 ms 0.472 ms
TUnit 428.60 ms 8.504 ms 15.973 ms
NUnit 696.71 ms 12.455 ms 16.626 ms
xUnit 688.65 ms 13.500 ms 17.073 ms
MSTest 623.95 ms 11.266 ms 17.869 ms
ubuntu-latest

BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2


Method Mean Error StdDev
TUnit_AOT 38.90 ms 1.028 ms 3.016 ms
TUnit 808.84 ms 16.100 ms 37.634 ms
NUnit 1,365.33 ms 25.078 ms 23.458 ms
xUnit 1,351.78 ms 16.635 ms 14.746 ms
MSTest 1,229.30 ms 20.256 ms 18.948 ms
windows-latest

BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2655) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2


Method Mean Error StdDev
TUnit_AOT 93.25 ms 0.810 ms 0.677 ms
TUnit 815.10 ms 15.859 ms 18.264 ms
NUnit 1,400.85 ms 12.235 ms 10.217 ms
xUnit 1,393.26 ms 17.837 ms 16.685 ms
MSTest 1,265.85 ms 10.265 ms 9.602 ms

Scenario: A test that takes 50ms to execute, repeated 100 times (including spawning a new process and initialising the test framework)

ubuntu-latest

BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2


Method Mean Error StdDev Median
TUnit_AOT 92.59 ms 1.883 ms 5.402 ms 91.12 ms
TUnit 883.00 ms 17.514 ms 38.443 ms 869.20 ms
NUnit 6,556.32 ms 15.384 ms 14.390 ms 6,557.96 ms
xUnit 6,555.72 ms 32.049 ms 29.979 ms 6,555.46 ms
MSTest 6,507.53 ms 20.884 ms 18.513 ms 6,510.20 ms
windows-latest

BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2655) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2


Method Mean Error StdDev Median
TUnit_AOT 148.0 ms 2.96 ms 5.70 ms 148.4 ms
TUnit 837.1 ms 16.59 ms 22.71 ms 840.8 ms
NUnit 8,620.0 ms 170.75 ms 452.81 ms 8,808.7 ms
xUnit 8,660.4 ms 172.15 ms 343.79 ms 8,788.3 ms
MSTest 8,619.5 ms 168.97 ms 329.57 ms 8,732.4 ms
macos-latest

BenchmarkDotNet v0.14.0, macOS Sonoma 14.6.1 (23G93) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 8.0.401
  [Host]     : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD


Method Mean Error StdDev Median
TUnit_AOT 250.6 ms 12.43 ms 36.45 ms 252.8 ms
TUnit 599.9 ms 20.94 ms 61.74 ms 617.0 ms
NUnit 14,096.1 ms 276.26 ms 413.49 ms 14,156.1 ms
xUnit 14,620.5 ms 291.66 ms 503.11 ms 14,624.3 ms
MSTest 14,385.0 ms 286.78 ms 517.13 ms 14,513.2 ms
Product Compatible and additional computed target framework versions.
.NET 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 (13)

Showing the top 5 NuGet packages that depend on TUnit:

Package Downloads
TUnit.Playwright

A .NET Testing Framework

TUnit.AspNetCore

A .NET Testing Framework

Saucery.TUnit

Sorcery for SauceLabs - Unlocking SauceLabs capability

TUnit.Aspire

A .NET Testing Framework

Rewrite.Test

Test harness for the automated code refactoring framework OpenRewrite.

GitHub repositories (70)

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.
reactiveui/refit
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
reactiveui/ReactiveUI
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
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.
HMBSbige/NatTypeTester
测试当前网络的 NAT 类型(STUN)
Cysharp/MagicOnion
Unified Realtime/API framework for .NET platform and Unity.
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.
dotnet/skills
Repository for skills to assist AI coding agents with .NET and C#
shouldly/shouldly
Should testing for .NET—the way assertions should be!
reactiveui/Akavache
An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important data as well as cached local data that expires.
OPCFoundation/UA-.NETStandard
OPC Unified Architecture .NET Standard
belav/csharpier
CSharpier is an opinionated code formatter for c#.
Cysharp/ConsoleAppFramework
Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
Nexus-Mods/NexusMods.App
Home of the development of the Nexus Mods App
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
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 and different functionality. Full documentation can be found at https://wiremock.org/dotnet/.
lookup-foundation/RevitLookup
Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
TNG/ArchUnitNET
A C# architecture test library to specify and assert architecture rules in C# for automated testing.
ncalc/ncalc
NCalc is a fast and lightweight expression evaluator library for .NET, designed for flexibility and high performance. It supports a wide range of mathematical and logical operations.
Version Downloads Last Updated
1.56.0 26,893 6/15/2026
1.55.2 9,293 6/14/2026
1.55.0 2,234 6/14/2026
1.54.0 9,413 6/12/2026
1.53.0 44,466 6/8/2026
1.51.0 10,857 6/7/2026
1.50.0 22,616 6/5/2026
1.49.0 14,600 6/3/2026
1.48.6 63,066 6/1/2026
1.48.0 5,249 5/31/2026
1.47.0 19,208 5/29/2026
1.46.0 4,959 5/28/2026
1.45.29 43,943 5/21/2026
1.45.22 11,507 5/20/2026
1.45.8 24,676 5/18/2026
1.45.0 14,878 5/18/2026
1.44.39 23,673 5/14/2026
1.44.0 55,577 5/10/2026
1.43.41 9,867 5/9/2026
0.1.653 424 9/11/2024
Loading failed