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 3.24GHz, 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.30 | 1.828 s | 0.0354 s | 0.0460 s | 1.831 s |
| Build_NUnit | 4.4.0 | 1.633 s | 0.0202 s | 0.0179 s | 1.633 s |
| Build_MSTest | 4.0.1 | 1.717 s | 0.0166 s | 0.0147 s | 1.716 s |
| Build_xUnit3 | 3.2.0 | 1.635 s | 0.0214 s | 0.0201 s | 1.634 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.30 | 541.8 ms | 3.38 ms | 3.16 ms | 542.0 ms |
| NUnit | 4.4.0 | 654.1 ms | 6.35 ms | 5.63 ms | 654.0 ms |
| MSTest | 4.0.1 | 625.8 ms | 5.42 ms | 4.53 ms | 625.4 ms |
| xUnit3 | 3.2.0 | 717.9 ms | 8.60 ms | 8.04 ms | 718.7 ms |
| TUnit_AOT | 1.0.30 | 123.0 ms | 0.32 ms | 0.30 ms | 122.9 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.30 | 501.16 ms | 4.557 ms | 3.805 ms | 503.78 ms |
| NUnit | 4.4.0 | 580.97 ms | 11.588 ms | 18.042 ms | 582.44 ms |
| MSTest | 4.0.1 | 587.95 ms | 9.871 ms | 8.751 ms | 588.34 ms |
| xUnit3 | 3.2.0 | 612.51 ms | 10.806 ms | 9.579 ms | 608.64 ms |
| TUnit_AOT | 1.0.30 | 26.02 ms | 0.355 ms | 0.332 ms | 25.95 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.30 | 572.4 ms | 6.95 ms | 5.80 ms | 572.9 ms |
| NUnit | 4.4.0 | 1,170.5 ms | 8.04 ms | 7.13 ms | 1,170.7 ms |
| MSTest | 4.0.1 | 2,953.6 ms | 8.62 ms | 7.64 ms | 2,952.1 ms |
| xUnit3 | 3.2.0 | 3,043.7 ms | 6.39 ms | 5.98 ms | 3,044.4 ms |
| TUnit_AOT | 1.0.30 | 130.7 ms | 0.65 ms | 0.58 ms | 130.8 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.30 | 554.83 ms | 6.074 ms | 5.682 ms | 554.19 ms |
| NUnit | 4.4.0 | 1,573.36 ms | 8.701 ms | 8.139 ms | 1,571.59 ms |
| MSTest | 4.0.1 | 1,526.75 ms | 10.786 ms | 10.089 ms | 1,526.09 ms |
| xUnit3 | 3.2.0 | 1,619.58 ms | 10.993 ms | 10.283 ms | 1,619.62 ms |
| TUnit_AOT | 1.0.30 | 79.80 ms | 0.468 ms | 0.437 ms | 79.72 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.30 | 494.79 ms | 3.391 ms | 3.172 ms | 494.06 ms |
| NUnit | 4.4.0 | 569.05 ms | 10.739 ms | 10.547 ms | 568.53 ms |
| MSTest | 4.0.1 | 483.48 ms | 8.017 ms | 6.694 ms | 483.72 ms |
| xUnit3 | 3.2.0 | 570.20 ms | 5.614 ms | 5.252 ms | 569.69 ms |
| TUnit_AOT | 1.0.30 | 41.52 ms | 0.956 ms | 2.819 ms | 41.47 ms |
