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.
# 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.6, 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 |
|---|---|---|---|---|---|
| Build_TUnit | 1.0.48 | 1.798 s | 0.0345 s | 0.0424 s | 1.785 s |
| Build_NUnit | 4.4.0 | 1.575 s | 0.0169 s | 0.0158 s | 1.573 s |
| Build_MSTest | 4.0.1 | 1.659 s | 0.0150 s | 0.0140 s | 1.658 s |
| Build_xUnit3 | 3.2.0 | 1.579 s | 0.0182 s | 0.0170 s | 1.575 s |
BenchmarkDotNet v0.15.6, 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 | 1.0.48 | 562.4 ms | 4.18 ms | 3.91 ms | 561.0 ms |
| NUnit | 4.4.0 | 679.2 ms | 7.24 ms | 6.41 ms | 679.6 ms |
| MSTest | 4.0.1 | 647.7 ms | 8.63 ms | 7.65 ms | 647.8 ms |
| xUnit3 | 3.2.0 | 744.4 ms | 11.90 ms | 10.55 ms | 741.5 ms |
| TUnit_AOT | 1.0.48 | 127.6 ms | 0.45 ms | 0.42 ms | 127.6 ms |
BenchmarkDotNet v0.15.6, 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 | 1.0.48 | 476.97 ms | 5.430 ms | 5.080 ms | 478.26 ms |
| NUnit | 4.4.0 | 537.80 ms | 6.692 ms | 6.260 ms | 537.55 ms |
| MSTest | 4.0.1 | 496.84 ms | 9.188 ms | 8.145 ms | 496.37 ms |
| xUnit3 | 3.2.0 | 584.15 ms | 10.733 ms | 10.039 ms | 582.13 ms |
| TUnit_AOT | 1.0.48 | 24.65 ms | 0.177 ms | 0.157 ms | 24.68 ms |
Scenario: Tests executing massively parallel workloads with CPU-bound, I/O-bound, and mixed operations
BenchmarkDotNet v0.15.6, 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 | 1.0.48 | 578.1 ms | 5.79 ms | 5.13 ms | 577.3 ms |
| NUnit | 4.4.0 | 1,220.5 ms | 7.43 ms | 6.20 ms | 1,220.9 ms |
| MSTest | 4.0.1 | 3,005.3 ms | 13.91 ms | 12.33 ms | 3,003.4 ms |
| xUnit3 | 3.2.0 | 3,096.0 ms | 11.11 ms | 10.40 ms | 3,094.6 ms |
| TUnit_AOT | 1.0.48 | 130.6 ms | 0.39 ms | 0.36 ms | 130.7 ms |
BenchmarkDotNet v0.15.6, 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 | 1.0.48 | 544.97 ms | 5.561 ms | 4.930 ms | 544.99 ms |
| NUnit | 4.4.0 | 1,540.60 ms | 5.644 ms | 4.713 ms | 1,540.91 ms |
| MSTest | 4.0.1 | 1,499.17 ms | 4.590 ms | 3.833 ms | 1,499.42 ms |
| xUnit3 | 3.2.0 | 1,591.72 ms | 6.560 ms | 6.136 ms | 1,592.55 ms |
| TUnit_AOT | 1.0.48 | 79.41 ms | 0.252 ms | 0.236 ms | 79.48 ms |
BenchmarkDotNet v0.15.6, 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 | 1.0.48 | 498.22 ms | 7.188 ms | 6.723 ms | 496.45 ms |
| NUnit | 4.4.0 | 584.65 ms | 11.669 ms | 11.461 ms | 582.38 ms |
| MSTest | 4.0.1 | 580.53 ms | 11.233 ms | 15.747 ms | 583.58 ms |
| xUnit3 | 3.2.0 | 587.89 ms | 8.750 ms | 7.757 ms | 586.15 ms |
| TUnit_AOT | 1.0.48 | 46.75 ms | 1.442 ms | 4.253 ms | 47.33 ms |
