TUnit is a next-generation testing framework for C# that outpaces traditional frameworks with source-generated tests, parallel execution by default, and Native AOT support. Built on the modern Microsoft.Testing.Platform, TUnit delivers faster test runs, better developer experience, and unmatched flexibility.
Feature | Traditional Frameworks | TUnit |
---|---|---|
Test Discovery | โ Runtime reflection | โ Compile-time generation |
Execution Speed | โ Sequential by default | โ Parallel by default |
Modern .NET | โ Full Native AOT & trimming | |
Test Dependencies | โ Not supported | โ
[DependsOn] chains |
Resource Management | โ Manual lifecycle | โ Intelligent cleanup |
โก Parallel by Default - Tests run concurrently with intelligent dependency management
๐ฏ Compile-Time Discovery - Know your test structure before runtime
๐ง Modern .NET Ready - Native AOT, trimming, and latest .NET features
๐ญ Extensible - Customize data sources, attributes, and test behavior
๐ New to TUnit? Start with our Getting Started Guide
๐ Migrating? See our Migration Guides
๐ฏ Advanced Features? Explore Data-Driven Testing, Test Dependencies, and Parallelism Control
dotnet new install TUnit.Templates
dotnet new TUnit -n "MyTestProject"
dotnet add package TUnit --prerelease
๐ ๐ Complete Documentation & Guides - Everything you need to master TUnit
๐ Performance & Modern Platform
|
๐ฏ Advanced Test Control
|
๐ Rich Data & Assertions
|
๐ง Developer Experience
|
[Test]
public async Task User_Creation_Should_Set_Timestamp()
{
// Arrange
var userService = new UserService();
// Act
var user = await userService.CreateUserAsync("john.doe@example.com");
// Assert - TUnit's fluent assertions
await Assert.That(user.CreatedAt)
.IsEqualTo(DateTime.Now)
.Within(TimeSpan.FromMinutes(1));
await Assert.That(user.Email)
.IsEqualTo("john.doe@example.com");
}
[Test]
[Arguments("user1@test.com", "ValidPassword123")]
[Arguments("user2@test.com", "AnotherPassword456")]
[Arguments("admin@test.com", "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 testing - tests all combinations
[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();
}
[Before(Class)]
public static async Task SetupDatabase(ClassHookContext context)
{
await DatabaseHelper.InitializeAsync();
}
[Test, DisplayName("Register a new account")]
[MethodDataSource(nameof(GetTestUsers))]
public async Task Register_User(string username, string password)
{
// Test implementation
}
[Test, DependsOn(nameof(Register_User))]
[Retry(3)] // Retry on failure
public async Task Login_With_Registered_User(string username, string password)
{
// This test runs after Register_User completes
}
[Test]
[ParallelLimit<LoadTestParallelLimit>] // Custom parallel control
[Repeat(100)] // Run 100 times
public async Task Load_Test_Homepage()
{
// Performance testing
}
// Custom attributes
[Test, WindowsOnly, RetryOnHttpError(5)]
public async Task Windows_Specific_Feature()
{
// Platform-specific test with custom retry logic
}
public class LoadTestParallelLimit : IParallelLimit
{
public int Limit => 10; // Limit to 10 concurrent executions
}
// Custom conditional execution
public class WindowsOnlyAttribute : SkipAttribute
{
public WindowsOnlyAttribute() : base("Windows only test") { }
public override Task<bool> ShouldSkip(TestContext testContext)
=> Task.FromResult(!OperatingSystem.IsWindows());
}
// Custom retry logic
public class RetryOnHttpErrorAttribute : RetryAttribute
{
public RetryOnHttpErrorAttribute(int times) : base(times) { }
public override Task<bool> ShouldRetry(TestInformation testInformation,
Exception exception, int currentRetryCount)
=> Task.FromResult(exception is HttpRequestException { StatusCode: HttpStatusCode.ServiceUnavailable });
}
[Test]
[Arguments(1, 2, 3)]
[Arguments(5, 10, 15)]
public async Task Calculate_Sum(int a, int b, int expected)
{
await Assert.That(Calculator.Add(a, b))
.IsEqualTo(expected);
} Fast, isolated, and reliable |
[Test, DependsOn(nameof(CreateUser))]
public async Task Login_After_Registration()
{
// Runs after CreateUser completes
var result = await authService.Login(user);
await Assert.That(result.IsSuccess).IsTrue();
} Stateful workflows made simple |
[Test]
[ParallelLimit<LoadTestLimit>]
[Repeat(1000)]
public async Task API_Handles_Concurrent_Requests()
{
await Assert.That(await httpClient.GetAsync("/api/health"))
.HasStatusCode(HttpStatusCode.OK);
} Built-in performance testing |
Tests are discovered at build time, not runtime - enabling faster discovery, better IDE integration, and precise resource lifecycle management.
Built for concurrency from day one with [DependsOn]
for test chains, [ParallelLimit]
for resource control, and intelligent scheduling.
The DataSourceGenerator<T>
pattern and custom attribute system let you extend TUnit's capabilities without modifying core framework code.
- ๐ Official Documentation - Comprehensive guides, tutorials, and API reference
- ๐ฌ GitHub Discussions - Get help and share ideas
- ๐ Issue Tracking - Report bugs and request features
- ๐ข Release Notes - Stay updated with latest improvements
TUnit works seamlessly across all major .NET development environments:
โ Fully supported - No additional configuration needed for latest versions
โ๏ธ Earlier versions: Enable "Use testing platform server mode" in Tools > Manage Preview Features
โ Fully supported
โ๏ธ Setup: Enable "Testing Platform support" in Settings > Build, Execution, Deployment > Unit Testing > VSTest
โ Fully supported
โ๏ธ Setup: Install C# Dev Kit and enable "Use Testing Platform Protocol"
โ
Full CLI support - Works with dotnet test
, dotnet run
, and direct executable execution
Package | Use Case |
---|---|
TUnit |
โญ Start here - Complete testing framework (includes Core + Engine + Assertions) |
TUnit.Core |
๐ Test libraries and shared components (no execution engine) |
TUnit.Engine |
๐ Test execution engine and adapter (for test projects) |
TUnit.Assertions |
โ Standalone assertions (works with any test framework) |
TUnit.Playwright |
๐ญ Playwright integration with automatic lifecycle management |
Coming from NUnit or xUnit? TUnit maintains familiar syntax while adding modern capabilities:
// Enhanced with TUnit's advanced features
[Test]
[Arguments("value1")]
[Arguments("value2")]
[Retry(3)]
[ParallelLimit<CustomLimit>]
public async Task Modern_TUnit_Test(string value) { }
๐ Need help migrating? Check our detailed Migration Guides with step-by-step instructions for xUnit, NUnit, and MSTest.
The API is mostly stable, but may have some changes based on feedback or issues before v1.0 release.
# Create a new test project with examples
dotnet new install TUnit.Templates && dotnet new TUnit -n "MyAwesomeTests"
# Or add to existing project
dotnet add package TUnit --prerelease
Optimized execution Parallel by default Zero reflection overhead |
Native AOT support Latest .NET features Source generation |
Compile-time checks Rich IDE integration Intelligent debugging |
Test dependencies Custom attributes Extensible architecture |
๐ Learn More: tunit.dev | ๐ฌ Get Help: GitHub Discussions | โญ Show Support: Star on GitHub
TUnit is actively developed and production-ready. Join our growing community of developers who've made the switch!
BenchmarkDotNet v0.15.2, macOS Sonoma 14.7.6 (23H626) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1,595.6 ms | 103.99 ms | 301.70 ms |
Build_NUnit | 1,056.8 ms | 59.48 ms | 164.82 ms |
Build_xUnit | 912.9 ms | 30.38 ms | 88.63 ms |
Build_MSTest | 1,014.8 ms | 49.25 ms | 143.65 ms |
BenchmarkDotNet v0.15.2, Linux Ubuntu 24.04.2 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.980 s | 0.0385 s | 0.0633 s |
Build_NUnit | 1.558 s | 0.0204 s | 0.0191 s |
Build_xUnit | 1.562 s | 0.0167 s | 0.0148 s |
Build_MSTest | 1.546 s | 0.0256 s | 0.0227 s |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3695) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.932 s | 0.0378 s | 0.0663 s |
Build_NUnit | 1.511 s | 0.0186 s | 0.0155 s |
Build_xUnit | 1.495 s | 0.0128 s | 0.0119 s |
Build_MSTest | 1.530 s | 0.0223 s | 0.0209 s |
Scenario: A single test that completes instantly (including spawning a new process and initialising the test framework)
BenchmarkDotNet v0.15.2, macOS Sonoma 14.7.6 (23H626) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 75.16 ms | 1.498 ms | 1.401 ms |
TUnit | 505.36 ms | 9.297 ms | 8.697 ms |
NUnit | 761.94 ms | 7.526 ms | 6.671 ms |
xUnit | 778.07 ms | 14.153 ms | 13.239 ms |
MSTest | 669.22 ms | 10.353 ms | 8.645 ms |
BenchmarkDotNet v0.15.2, Linux Ubuntu 24.04.2 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 27.06 ms | 0.683 ms | 2.002 ms |
TUnit | 799.36 ms | 15.912 ms | 17.686 ms |
NUnit | 1,250.46 ms | 9.743 ms | 9.114 ms |
xUnit | 1,310.10 ms | 11.987 ms | 11.213 ms |
MSTest | 1,099.07 ms | 8.472 ms | 7.511 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3695) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 77.63 ms | 1.480 ms | 1.236 ms |
TUnit | 886.34 ms | 17.228 ms | 24.151 ms |
NUnit | 1,329.44 ms | 7.524 ms | 7.038 ms |
xUnit | 1,373.73 ms | 12.595 ms | 11.781 ms |
MSTest | 1,186.50 ms | 15.886 ms | 14.860 ms |
Scenario: A test that takes 50ms to execute, repeated 100 times (including spawning a new process and initialising the test framework)
BenchmarkDotNet v0.15.2, macOS Sonoma 14.7.6 (23H626) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 238.1 ms | 12.41 ms | 36.58 ms |
TUnit | 816.6 ms | 28.06 ms | 82.74 ms |
NUnit | 14,291.4 ms | 272.89 ms | 477.94 ms |
xUnit | 14,611.0 ms | 291.51 ms | 547.52 ms |
MSTest | 14,384.8 ms | 285.63 ms | 550.30 ms |
BenchmarkDotNet v0.15.2, Linux Ubuntu 24.04.2 LTS (Noble Numbat)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 76.03 ms | 1.492 ms | 2.493 ms |
TUnit | 885.15 ms | 17.640 ms | 19.606 ms |
NUnit | 6,271.44 ms | 11.212 ms | 10.487 ms |
xUnit | 6,413.22 ms | 13.201 ms | 11.703 ms |
MSTest | 6,245.45 ms | 17.681 ms | 14.764 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3695) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.301
[Host] : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.6 (9.0.625.26613), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 112.3 ms | 2.19 ms | 3.66 ms |
TUnit | 945.1 ms | 18.85 ms | 23.14 ms |
NUnit | 7,548.9 ms | 26.31 ms | 24.61 ms |
xUnit | 7,602.0 ms | 28.37 ms | 26.54 ms |
MSTest | 7,453.2 ms | 28.85 ms | 26.99 ms |