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 | Median |
---|---|---|---|---|
Build_TUnit | 1,155.9 ms | 100.66 ms | 293.62 ms | 1,024.3 ms |
Build_NUnit | 954.3 ms | 36.00 ms | 102.72 ms | 922.2 ms |
Build_xUnit | 808.8 ms | 16.16 ms | 39.63 ms | 795.7 ms |
Build_MSTest | 845.1 ms | 16.86 ms | 23.63 ms | 845.3 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.887 s | 0.0356 s | 0.0365 s |
Build_NUnit | 1.444 s | 0.0067 s | 0.0056 s |
Build_xUnit | 1.451 s | 0.0084 s | 0.0074 s |
Build_MSTest | 1.466 s | 0.0168 s | 0.0149 s |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3807) (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.914 s | 0.0380 s | 0.0665 s |
Build_NUnit | 1.524 s | 0.0247 s | 0.0274 s |
Build_xUnit | 1.497 s | 0.0204 s | 0.0191 s |
Build_MSTest | 1.549 s | 0.0277 s | 0.0259 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 | 71.86 ms | 1.433 ms | 1.705 ms |
TUnit | 490.61 ms | 9.777 ms | 13.052 ms |
NUnit | 719.63 ms | 11.366 ms | 9.491 ms |
xUnit | 739.33 ms | 10.350 ms | 9.175 ms |
MSTest | 638.24 ms | 7.852 ms | 7.345 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.38 ms | 0.631 ms | 1.851 ms |
TUnit | 823.08 ms | 16.401 ms | 17.549 ms |
NUnit | 1,284.85 ms | 9.477 ms | 8.865 ms |
xUnit | 1,340.51 ms | 7.680 ms | 6.808 ms |
MSTest | 1,134.80 ms | 10.309 ms | 9.643 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3807) (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 | 57.68 ms | 2.044 ms | 5.961 ms |
TUnit | 891.21 ms | 17.791 ms | 29.725 ms |
NUnit | 1,347.95 ms | 26.466 ms | 40.417 ms |
xUnit | 1,369.70 ms | 19.552 ms | 18.289 ms |
MSTest | 1,192.19 ms | 12.730 ms | 11.908 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 | 242.6 ms | 11.95 ms | 35.22 ms |
TUnit | 696.1 ms | 26.44 ms | 77.95 ms |
NUnit | 14,178.1 ms | 281.82 ms | 536.20 ms |
xUnit | 14,591.6 ms | 291.78 ms | 409.04 ms |
MSTest | 14,185.7 ms | 283.70 ms | 546.59 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 | Median |
---|---|---|---|---|
TUnit_AOT | 75.65 ms | 1.507 ms | 2.600 ms | 74.17 ms |
TUnit | 891.43 ms | 17.608 ms | 22.268 ms | 882.31 ms |
NUnit | 6,274.67 ms | 17.918 ms | 15.883 ms | 6,271.88 ms |
xUnit | 6,465.20 ms | 17.665 ms | 16.524 ms | 6,467.17 ms |
MSTest | 6,257.33 ms | 22.718 ms | 21.250 ms | 6,263.69 ms |
BenchmarkDotNet v0.15.2, Windows 10 (10.0.20348.3807) (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 | Median |
---|---|---|---|---|
TUnit_AOT | 112.1 ms | 2.21 ms | 4.10 ms | 109.6 ms |
TUnit | 962.8 ms | 18.95 ms | 25.94 ms | 959.9 ms |
NUnit | 7,524.2 ms | 26.08 ms | 24.40 ms | 7,533.6 ms |
xUnit | 7,581.6 ms | 20.99 ms | 18.61 ms | 7,580.5 ms |
MSTest | 7,461.6 ms | 24.73 ms | 23.13 ms | 7,453.9 ms |