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.
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");}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- ASP.NET CoreEndpoints with isolated clients
- AspireYour whole distributed app
- PlaywrightA clean browser page per test
- TUnit.MocksSource-generated, AOT-safe mocks
Turn your first bar green.
dotnet new install TUnit.Templatesdotnet new TUnit -n MyTestsdotnet 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