TUnit.Core 0.1.402-alpha01

Prefix Reserved
This is a prerelease version of TUnit.Core.
There is a newer version of this package available.
See the version list below for details.
dotnet add package TUnit.Core --version 0.1.402-alpha01
                    
NuGet\Install-Package TUnit.Core -Version 0.1.402-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.Core" Version="0.1.402-alpha01" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TUnit.Core" Version="0.1.402-alpha01" />
                    
Directory.Packages.props
<PackageReference Include="TUnit.Core" />
                    
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.Core --version 0.1.402-alpha01
                    
#r "nuget: TUnit.Core, 0.1.402-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.Core@0.1.402-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.Core&version=0.1.402-alpha01&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TUnit.Core&version=0.1.402-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
  • Parallel by default, with mechanisms to switch it off for certain tests
  • Test ordering (if running not in parallel)
  • Tests can depend on other tests to form chains
  • Easy to read assertions
  • Injectable test data functionality
  • Hooks before and after: Assembly, Class, Test
  • Designed to avoid common pitfalls such as leaky test states
  • Ability to view metadata and results (if in a cleanup method) for a test from a TestContext object

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

    [BeforeAllTestsInClass]
    public static async Task ClearDatabase() { ... }

    [AfterAllTestsInClass]
    public static async Task AssertDatabaseIsAsExpected() { ... }

    [BeforeEachTest]
    public async Task CreatePlaywrightBrowser() { ... }

    [AfterEachTest]
    public async Task DisposePlaywrightBrowser() { ... }

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

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

    [DataSourceDrivenTest, DependsOn(nameof(Login))]
    [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)]
    [DataDrivenTest]
    [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]
    [Property("Some Key", "Some Value")]
    public async Task Ping() { ... }

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

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 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.
  • net8.0

    • No dependencies.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on TUnit.Core:

Package Downloads
TUnit.Engine

A .NET Testing Framework

Verify.TUnit

Enables verification of complex models and documents.

Rocket.Surgery.Extensions.Testing.TUnit

Package Description

NetEvolve.Extensions.TUnit

This library provides various compatibility features between `NUnit`, `XUnit`, `XUnit.V3`, `TUnit` and `MSTest`.

Reqnroll.TUnit

Package to use Reqnroll with TUnit 1.3.25 and later.

GitHub repositories (8)

Showing the top 8 popular GitHub repositories that depend on TUnit.Core:

Repository Stars
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.
VerifyTests/Verify
Verify is a snapshot testing tool that simplifies the assertion of complex data models and documents.
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/.
reqnroll/Reqnroll
Open-source Cucumber-style BDD test automation framework for .NET.
Eventuous/eventuous
Event Sourcing library for .NET
thomhurst/ModularPipelines
Write your pipelines in C# !
SwissLife-OSS/snapshooter
Snapshooter is a snapshot testing tool for .NET Core and .NET Framework
DamianMorozov/OpenTgResearcher
OpenTgResearcher - tool for analyzing Telegram chats and downloading their content
Version Downloads Last Updated
1.13.56 0 2/12/2026
1.13.54 0 2/12/2026
1.13.51 382 2/12/2026
1.13.48 399 2/12/2026
1.13.47 204 2/11/2026
1.13.40 2,657 2/10/2026
1.13.30 611 2/10/2026
1.13.27 683 2/10/2026
1.13.24 407 2/10/2026
1.13.11 9,306 2/7/2026
1.13.8 489 2/6/2026
1.13.0 1,614 2/6/2026
1.12.147 1,626 2/6/2026
1.12.144 1,366 2/5/2026
1.12.139 3,115 2/5/2026
1.12.125 8,779 2/2/2026
1.12.111 9,493 2/1/2026
1.12.102 1,690 1/31/2026
1.12.93 4,858 1/29/2026
0.1.402-alpha01 154 7/5/2024
Loading failed