TUnit is a modern testing framework for .NET that uses source-generated tests, parallel execution by default, and Native AOT support. Built on Microsoft.Testing.Platform, it's faster than traditional reflection-based frameworks and gives you more control over how your tests run.
| Feature | Traditional Frameworks | TUnit |
|---|---|---|
| Test Discovery | ❌ Runtime reflection | ✅ Compile-time generation |
| Execution Speed | ❌ Sequential by default | ✅ Parallel by default |
| Modern .NET | ✅ Native AOT & trimming | |
| Test Dependencies | ❌ Not supported | ✅ [DependsOn] chains |
| Resource Management | ❌ Manual lifecycle | ✅ Automatic cleanup |
Parallel by Default - Tests run concurrently with dependency management
Compile-Time Discovery - Test structure is known 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 the Getting Started Guide
Migrating? See the Migration Guides
Learn more: Data-Driven Testing, Test Dependencies, Parallelism Control
dotnet new install TUnit.Templates
dotnet new TUnit -n "MyTestProject"dotnet add package TUnit --prerelease📖 Complete Documentation & Guides
|
Performance
|
Test Control
|
|
Data & Assertions
|
Developer Tools
|
[Test]
public async Task User_Creation_Should_Set_Timestamp()
{
// Arrange
var userService = new UserService();
// Act
var user = await userService.CreateUserAsync("[email protected]");
// Assert - TUnit's fluent assertions
await Assert.That(user.CreatedAt)
.IsEqualTo(DateTime.Now)
.Within(TimeSpan.FromMinutes(1));
await Assert.That(user.Email)
.IsEqualTo("[email protected]");
}[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 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);
} |
[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();
} |
[Test]
[ParallelLimit<LoadTestLimit>]
[Repeat(1000)]
public async Task API_Handles_Concurrent_Requests()
{
await Assert.That(await httpClient.GetAsync("/api/health"))
.HasStatusCode(HttpStatusCode.OK);
} |
Tests are discovered at build time, not runtime. This means faster discovery, better IDE integration, and more predictable resource management.
Tests run in parallel by default. Use [DependsOn] to chain tests together, and [ParallelLimit] to control resource usage.
The DataSourceGenerator<T> pattern and custom attribute system let you extend TUnit without modifying the framework.
- Official Documentation - Guides, tutorials, and API reference
- GitHub Discussions - Get help and share ideas
- Issue Tracking - Report bugs and request features
- Release Notes - Latest updates and changes
TUnit works with all major .NET IDEs:
✅ 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 > Testing Platform
✅ 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 uses familiar syntax with some additions:
// TUnit test with dependency management and retries
[Test]
[Arguments("value1")]
[Arguments("value2")]
[Retry(3)]
[ParallelLimit<CustomLimit>]
public async Task Modern_TUnit_Test(string value) { }📖 Need help migrating? Check our Migration Guides for xUnit, NUnit, and MSTest.
The API is mostly stable, but may have some changes based on feedback before the v1.0 release.
# Create a new test project
dotnet new install TUnit.Templates && dotnet new TUnit -n "MyTestProject"
# Or add to existing project
dotnet add package TUnit --prereleaseLearn More: tunit.dev | Get Help: GitHub Discussions | Star on GitHub: github.com/thomhurst/TUnit
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.79GHz), 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| Build_TUnit | 0.86.10 | 1.745 s | 0.0348 s | 0.0326 s | 1.746 s |
| Build_NUnit | 4.4.0 | 1.543 s | 0.0158 s | 0.0148 s | 1.538 s |
| Build_MSTest | 4.0.1 | 1.613 s | 0.0197 s | 0.0184 s | 1.616 s |
| Build_xUnit3 | 3.1.0 | 1.513 s | 0.0157 s | 0.0147 s | 1.518 s |
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| TUnit | 0.86.10 | 550.3 ms | 5.18 ms | 4.84 ms | 549.2 ms |
| NUnit | 4.4.0 | 699.9 ms | 6.28 ms | 5.88 ms | 700.4 ms |
| MSTest | 4.0.1 | 667.9 ms | 7.47 ms | 6.23 ms | 666.9 ms |
| xUnit3 | 3.1.0 | 641.9 ms | 3.04 ms | 2.84 ms | 641.9 ms |
| TUnit_AOT | 0.86.10 | 173.8 ms | 0.58 ms | 0.54 ms | 173.9 ms |
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| TUnit | 0.86.10 | 519.03 ms | 5.999 ms | 5.611 ms | 519.52 ms |
| NUnit | 4.4.0 | 619.54 ms | 12.145 ms | 17.025 ms | 614.65 ms |
| MSTest | 4.0.1 | 632.36 ms | 12.544 ms | 12.319 ms | 631.28 ms |
| xUnit3 | 3.1.0 | 507.74 ms | 4.370 ms | 4.087 ms | 506.88 ms |
| TUnit_AOT | 0.86.10 | 74.88 ms | 0.324 ms | 0.303 ms | 74.93 ms |
Scenario: Tests executing massively parallel workloads with CPU-bound, I/O-bound, and mixed operations
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.79GHz), 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| TUnit | 0.86.10 | 696.8 ms | 5.14 ms | 4.81 ms | 696.1 ms |
| NUnit | 4.4.0 | 1,202.2 ms | 6.87 ms | 6.09 ms | 1,202.2 ms |
| MSTest | 4.0.1 | 3,001.0 ms | 5.96 ms | 5.28 ms | 3,001.6 ms |
| xUnit3 | 3.1.0 | 2,966.4 ms | 8.21 ms | 7.28 ms | 2,964.4 ms |
| TUnit_AOT | 0.86.10 | 279.2 ms | 0.66 ms | 0.62 ms | 279.1 ms |
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| TUnit | 0.86.10 | 626.5 ms | 6.15 ms | 5.75 ms | 624.8 ms |
| NUnit | 4.4.0 | 1,535.8 ms | 10.02 ms | 8.37 ms | 1,533.9 ms |
| MSTest | 4.0.1 | 1,499.8 ms | 9.65 ms | 9.03 ms | 1,499.5 ms |
| xUnit3 | 3.1.0 | 1,517.8 ms | 5.74 ms | 5.37 ms | 1,516.8 ms |
| TUnit_AOT | 0.86.10 | 177.0 ms | 0.49 ms | 0.43 ms | 177.0 ms |
BenchmarkDotNet v0.15.5, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100-rc.2.25502.107
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Job-GVKUBM : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v3
Runtime=.NET 10.0
| Method | Version | Mean | Error | StdDev | Median |
|---|---|---|---|---|---|
| TUnit | 0.86.10 | 520.12 ms | 6.200 ms | 5.496 ms | 519.39 ms |
| NUnit | 4.4.0 | 688.25 ms | 8.293 ms | 7.757 ms | 686.78 ms |
| MSTest | 4.0.1 | 686.01 ms | 11.597 ms | 10.280 ms | 687.04 ms |
| xUnit3 | 3.1.0 | 492.65 ms | 3.582 ms | 3.176 ms | 492.63 ms |
| TUnit_AOT | 0.86.10 | 80.02 ms | 0.194 ms | 0.162 ms | 79.99 ms |
