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.303
[Host] : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
Build_TUnit | 1,136.2 ms | 48.74 ms | 139.06 ms | 1,124.5 ms |
Build_NUnit | 910.2 ms | 35.17 ms | 103.14 ms | 860.6 ms |
Build_xUnit | 903.3 ms | 29.28 ms | 86.35 ms | 874.7 ms |
Build_MSTest | 935.7 ms | 37.50 ms | 109.98 ms | 905.5 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.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.926 s | 0.0380 s | 0.0624 s |
Build_NUnit | 1.472 s | 0.0121 s | 0.0113 s |
Build_xUnit | 1.460 s | 0.0214 s | 0.0179 s |
Build_MSTest | 1.501 s | 0.0165 s | 0.0146 s |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3932) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.911 s | 0.0373 s | 0.0444 s |
Build_NUnit | 1.495 s | 0.0297 s | 0.0278 s |
Build_xUnit | 1.482 s | 0.0209 s | 0.0185 s |
Build_MSTest | 1.517 s | 0.0243 s | 0.0227 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.303
[Host] : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 82.60 ms | 3.147 ms | 9.080 ms |
TUnit | 649.41 ms | 36.666 ms | 105.202 ms |
NUnit | 876.07 ms | 35.812 ms | 99.829 ms |
xUnit | 807.77 ms | 26.687 ms | 78.268 ms |
MSTest | 634.35 ms | 12.253 ms | 10.232 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.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 27.65 ms | 0.646 ms | 1.893 ms |
TUnit | 820.54 ms | 16.372 ms | 20.705 ms |
NUnit | 1,287.00 ms | 9.767 ms | 8.658 ms |
xUnit | 1,337.24 ms | 10.540 ms | 9.344 ms |
MSTest | 1,131.11 ms | 8.561 ms | 8.008 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3932) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
TUnit_AOT | 55.28 ms | 1.754 ms | 5.145 ms | 53.25 ms |
TUnit | 875.75 ms | 17.122 ms | 25.097 ms | 867.35 ms |
NUnit | 1,323.39 ms | 20.203 ms | 18.898 ms | 1,324.68 ms |
xUnit | 1,383.00 ms | 26.391 ms | 28.238 ms | 1,376.62 ms |
MSTest | 1,189.53 ms | 22.606 ms | 22.202 ms | 1,187.44 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.303
[Host] : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), Arm64 RyuJIT AdvSIMD
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 318.0 ms | 21.33 ms | 62.21 ms |
TUnit | 1,163.3 ms | 63.03 ms | 184.86 ms |
NUnit | 13,693.9 ms | 269.97 ms | 592.59 ms |
xUnit | 13,769.1 ms | 273.61 ms | 628.66 ms |
MSTest | 13,470.3 ms | 267.96 ms | 509.81 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.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
TUnit_AOT | 74.76 ms | 1.462 ms | 2.319 ms | 73.45 ms |
TUnit | 885.91 ms | 17.152 ms | 18.352 ms | 877.05 ms |
NUnit | 6,273.76 ms | 13.329 ms | 12.468 ms | 6,270.47 ms |
xUnit | 6,431.33 ms | 13.438 ms | 12.569 ms | 6,431.51 ms |
MSTest | 6,244.48 ms | 10.586 ms | 9.903 ms | 6,246.55 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3932) (Hyper-V)
AMD EPYC 7763 2.44GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.303
[Host] : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
.NET 9.0 : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX2
Job=.NET 9.0 Runtime=.NET 9.0
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
TUnit_AOT | 112.3 ms | 2.22 ms | 4.23 ms | 109.6 ms |
TUnit | 950.8 ms | 18.11 ms | 23.54 ms | 940.1 ms |
NUnit | 7,502.1 ms | 22.34 ms | 20.90 ms | 7,497.3 ms |
xUnit | 7,573.7 ms | 18.88 ms | 17.66 ms | 7,570.8 ms |
MSTest | 7,437.2 ms | 17.74 ms | 14.82 ms | 7,436.6 ms |