Skip to main content
net8.0net9.0net10.0.NETStandard2.0

A .NET Testing Framework

Published
May 8, 2026
5mo ago
Total Downloads
25.7K
25,669

Install

dotnet add package TUnit.Assertions.Should --version 1.43.38-beta
ProductVersions
.NET
net10.0net8.0net9.0
.NET Standard
netstandard2.0

README

TUnit

TUnit

A modern .NET testing framework. Tests are source-generated at compile time, run in parallel by default, and support Native AOT β€” all built on Microsoft.Testing.Platform.

thomhurst%2FTUnit | Trendshift

Codacy Badge GitHub Repo stars GitHub Issues or Pull Requests GitHub Sponsors nuget NuGet Downloads GitHub Workflow Status (with event) GitHub last commit (branch) License

Features

  • Compile-time test discovery β€” tests are generated at build time rather than discovered via reflection at runtime, which means faster startup and better IDE integration
  • Parallel by default β€” tests run concurrently; use [DependsOn] to express ordering and [ParallelLimiter] to cap concurrency
  • Data-driven testing β€” [Arguments], [Matrix], [ClassData], and custom DataSourceGenerator<T> sources
  • Async assertions with detailed failure messages
  • Built-in Roslyn analyzers β€” catch mistakes at compile time, such as missing async, incorrect method signatures, and invalid attribute combinations
  • Extensible β€” write your own skip conditions, retry logic, and attributes
  • Native AOT & trimming support
  • Lifecycle hooks β€” [Before] / [After] at method, class, assembly, or test session scope

Getting Started

Using the Project Template (Recommended)

dotnet new install TUnit.Templates
dotnet new TUnit -n "MyTestProject"
cd MyTestProject
dotnet run

Manual Installation

dotnet add package TUnit

Getting Started Guide Β· Migration Guides

Examples

Basic test with assertions

[Test]
public async Task Parsing_A_Valid_Date_Succeeds()
{
    var date = DateTime.Parse("2025-01-01");

    await Assert.That(date.Year).IsEqualTo(2025);
    await Assert.That(date.Month).IsEqualTo(1);
}

Data-driven tests

[Test]
[Arguments("[email protected]", "ValidPassword123")]
[Arguments("[email protected]", "AnotherPassword456")]
[Arguments("[email protected]", "AdminPass789")]
public async Task User_Login_Should_Succeed(string email, string password)
{
    var result = await authService.LoginAsync(email, password);
    await Assert.That(result.IsSuccess).IsTrue();
}

// Matrix β€” generates a test for every combination (9 total here)
[Test]
[MatrixDataSource]
public async Task Database_Operations_Work(
    [Matrix("Create", "Update", "Delete")] string operation,
    [Matrix("User", "Product", "Order")] string entity)
{
    await Assert.That(await ExecuteOperation(operation, entity))
        .IsTrue();
}

Hooks, dependencies, and retry

[Before(Class)]
public static async Task SetupDatabase(ClassHookContext context)
{
    await DatabaseHelper.InitializeAsync();
}

[Test]
[MethodDataSource(nameof(GetTestUsers))]
public async Task Register_User(string username, string password) { ... }

[Test, DependsOn(nameof(Register_User))]
[Retry(3)]
public async Task Login_With_Registered_User(string username, string password)
{
    // Guaranteed to run after Register_User passes
}

Custom attributes

Extend built-in base classes to create your own skip conditions, retry logic, and more:

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

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

[Test, WindowsOnly]
public async Task Windows_Specific_Feature() { ... }

See the documentation for more examples, including custom retry logic and data sources.

IDE Support

IDE Notes
Visual Studio 2022 (17.13+) Works out of the box
Visual Studio 2022 (earlier) Enable "Use testing platform server mode" in Tools > Manage Preview Features
JetBrains Rider Enable "Testing Platform support" in Settings > Build, Execution, Deployment > Unit Testing > Testing Platform
VS Code Install C# Dev Kit and enable "Use Testing Platform Protocol"
CLI Works with dotnet test, dotnet run, and direct execution

Packages

Package Purpose
TUnit Start here β€” the full framework (Core + Engine + Assertions)
TUnit.Core Shared test library components without an execution engine
TUnit.Engine Execution engine for test projects
TUnit.Assertions Standalone assertions β€” works with other test frameworks too
TUnit.Assertions.Should Optional FluentAssertions-style value.Should().BeEqualTo(...) syntax over TUnit.Assertions (beta)
TUnit.Playwright Playwright integration with automatic browser lifecycle management

Migrating from xUnit, NUnit, or MSTest?

The syntax will feel familiar. For example, xUnit's [Fact] becomes [Test], and [Theory] + [InlineData] becomes [Test] + [Arguments]. See the migration guides for full details: xUnit Β· NUnit Β· MSTest.

Community

Changes from Previous Version

No structural changes between v1.43.37-beta and v1.43.38-beta.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.