Skip to main content

Keep it green.

TUnit is a testing framework for modern .NET. Tests are discovered while you build and run in parallel by default, so you get to green sooner.

Each square is one test, run by one of 12 workers. Darker squares took longer. Point at one to see its name.

Our claims, written as tests.

Open any result to see the code behind it.

Discovers_tests_at_compile_timePassed

A source generator writes the code that registers every test while your project builds. Nothing scans assemblies with reflection at startup, so the first test starts straight away, and test projects can publish with Native AOT.

Native AOT support
[Test]
public async Task Total_includes_tax()
{
var cart = new Cart(new Item(100m));
await Assert.That(cart.Total()).IsEqualTo(108m);
}
Runs_tests_in_parallel_by_defaultPassed

Every test runs concurrently unless you say otherwise. When tests share something, say so with an attribute: keep them apart, limit how many run at once, or make one wait for another.

Control parallel execution
[Test, NotInParallel("Database")]
public async Task Migrates_schema() { /* ... */ }
[Test, DependsOn(nameof(Migrates_schema))]
public async Task Seeds_reference_data() { /* ... */ }
Turns_one_method_into_many_casesPassed

Feed a test from attributes, methods, classes, or a matrix of values. Each case is reported on its own, with its arguments in the name.

Data-driven tests
[Test]
[Arguments(1, 2, 3)]
[Arguments(5, 8, 13)]
[Arguments(-1, 1, 0)]
public async Task Add(int a, int b, int expected)
{
await Assert.That(a + b).IsEqualTo(expected);
}
Flags_assertions_you_forgot_to_awaitPassed

Assertions are awaited and read left to right. Analyzers check them while you type, along with hook signatures and data sources, so mistakes show up in the editor instead of in CI.

Awaiting assertions
[Test]
public async Task Greeting_contains_name()
{
var greeting = Greet("Ada");
Assert.That(greeting).Contains("Ada");
}
TUnitAssertions0002Assert statements must be awaited - all TUnit assertions return Task
Tests_whole_systems_not_just_unitsPassed

The same framework drives integration tests, with shared infrastructure that starts once and is cleaned up after the last test using it finishes.

See the benchmarks

Turn your first bar green.

  1. dotnet new install TUnit.Templates
  2. dotnet new TUnit -n MyTests
  3. dotnet run --project MyTests

 

Write your first test

Moving from xUnit, NUnit, or MSTest?

The migration guides map each attribute, assertion, and hook you use today to its TUnit equivalent.

Compare frameworks