Skip to main content

TUNITTesting Made Simple

Modern .NET Testing

A modern .NET testing framework where tests are discovered at compile time, not reflected at runtime. Source-generated and Native AOT ready, parallel by default, batteries included — assertions, mocking, and first-class ASP.NET Core, Aspire, and Playwright integrations.

SourceGenerated
AOTCompatible
ParallelExecution
CalculatorTests.cs
[Test]
public async Task MyTest()
{
// Arrange
var calculator = new Calculator();

// Act
var result = calculator.Add(2, 3);

// Assert
await Assert.That(result).IsEqualTo(5);
}
Test Results
MyTest 2ms
1 test passed • 0 failed • 2ms total

Quick Start

Get up and running in seconds

1

Install

dotnet add package TUnit
2

Write

[Test]
public async Task TestAddition()
{
await Assert.That(1 + 1).IsEqualTo(2);
}
3

Run

dotnet test

Choose Your Journey

Where would you like to start?

🚀

New to TUnit

Start from scratch and learn the fundamentals

🔄

Migrating to TUnit

Switch to TUnit from xUnit, NUnit, or MSTest

🎯

Advanced & Optimization

Optimize performance and extend TUnit

Core Features

Everything you need for modern test development

🔧

Flexible Test Design

Data-driven arguments, matrix tests, and custom data sources — plus injectable, shared fixtures with dependency injection and reference-counted disposal.

[Test]
[Arguments(1, 2, 3)]
[Arguments(4, 5, 9)]
public async Task TestAdd(int a, int b, int expected)
{
await Assert.That(a + b).IsEqualTo(expected);
}

Intuitive Syntax

Clean, attribute-based tests with fluent async assertions that read like sentences — and pinpoint the exact difference when they fail, instead of dumping object graphs at you.

[Test]
public async Task TestAsync()
{
var result = await GetDataAsync();
await Assert.That(result)
.IsNotNull()
.And.Count().IsEqualTo(5);
}

Performance Optimized

Source-generated tests with Native AOT support, built on the Microsoft Testing Platform. Work shifts from run time to build time, so every run after starts faster.

// AOT Compatible
[Test]
public async Task PerformantTest()
{
// Source generated
// No reflection overhead
await Assert.That(true).IsTrue();
}

Why TUnit?

Built for modern .NET development

Compile-Time Discovery

Tests are wired up by a source generator at build time, not found via reflection at runtime — faster startup, better IDE integration, and full Native AOT / trimming support.

🎯

Compile-Time Safety

A suite of Roslyn analyzers ships in the box, so invalid hook signatures, broken data sources, and misused assertions fail your build — not your CI run.

🔀

Parallel by Default

Tests run concurrently out of the box; [DependsOn], [NotInParallel], and [ParallelLimiter<T>] give you precise ordering and throttling when you need it.

🧩

Batteries Included

Rich async assertions, shared fixtures with dependency injection, and lifecycle hooks at every scope — plus a source-generated mocking library.

🔌

First-Class Integrations

Purpose-built support for ASP.NET Core, Aspire, and Playwright, so integration and end-to-end tests feel native to the framework.

🚀

AOT & Trimming Ready

Native AOT support enables dramatically faster startup and reduced memory usage, with no runtime reflection to trim away.