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("[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);
} 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 |
---|---|---|---|
Build_TUnit | 970.0 ms | 19.15 ms | 41.63 ms |
Build_NUnit | 811.1 ms | 14.30 ms | 11.94 ms |
Build_xUnit | 780.0 ms | 6.88 ms | 5.75 ms |
Build_MSTest | 839.8 ms | 16.55 ms | 16.26 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.943 s | 0.0381 s | 0.0646 s |
Build_NUnit | 1.513 s | 0.0158 s | 0.0132 s |
Build_xUnit | 1.480 s | 0.0239 s | 0.0200 s |
Build_MSTest | 1.497 s | 0.0139 s | 0.0116 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 | 2.054 s | 0.0404 s | 0.0604 s |
Build_NUnit | 1.612 s | 0.0118 s | 0.0104 s |
Build_xUnit | 1.568 s | 0.0275 s | 0.0257 s |
Build_MSTest | 1.624 s | 0.0169 s | 0.0158 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 | 81.07 ms | 1.256 ms | 1.049 ms |
TUnit | 520.64 ms | 8.869 ms | 15.299 ms |
NUnit | 766.03 ms | 15.073 ms | 16.128 ms |
xUnit | 904.52 ms | 45.525 ms | 134.230 ms |
MSTest | 745.57 ms | 26.095 ms | 76.942 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 | 28.77 ms | 0.998 ms | 2.926 ms |
TUnit | 854.10 ms | 16.766 ms | 24.045 ms |
NUnit | 1,325.45 ms | 13.246 ms | 12.390 ms |
xUnit | 1,375.86 ms | 10.955 ms | 10.247 ms |
MSTest | 1,155.49 ms | 8.148 ms | 7.223 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 | 54.27 ms | 1.680 ms | 4.847 ms |
TUnit | 887.77 ms | 17.639 ms | 28.484 ms |
NUnit | 1,332.07 ms | 13.404 ms | 12.538 ms |
xUnit | 1,376.46 ms | 12.603 ms | 11.789 ms |
MSTest | 1,183.10 ms | 16.320 ms | 15.266 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 | 240.7 ms | 11.88 ms | 35.04 ms |
TUnit | 637.6 ms | 20.15 ms | 59.42 ms |
NUnit | 14,033.3 ms | 279.42 ms | 261.37 ms |
xUnit | 14,497.3 ms | 285.91 ms | 570.99 ms |
MSTest | 14,354.9 ms | 281.80 ms | 508.14 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.94 ms | 1.519 ms | 2.273 ms | 74.61 ms |
TUnit | 892.03 ms | 17.504 ms | 22.137 ms | 888.38 ms |
NUnit | 6,274.85 ms | 15.360 ms | 14.368 ms | 6,279.06 ms |
xUnit | 6,424.84 ms | 8.771 ms | 7.325 ms | 6,422.71 ms |
MSTest | 6,260.19 ms | 8.368 ms | 6.988 ms | 6,262.44 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 | 112.9 ms | 2.22 ms | 3.11 ms |
TUnit | 966.0 ms | 19.11 ms | 28.60 ms |
NUnit | 7,520.8 ms | 21.50 ms | 20.11 ms |
xUnit | 7,598.5 ms | 37.60 ms | 35.17 ms |
MSTest | 7,454.3 ms | 25.53 ms | 23.88 ms |