Skip to content

thomhurst/TUnit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 The Modern Testing Framework for .NET

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.

thomhurst%2FTUnit | Trendshift

Codacy BadgeGitHub Repo stars GitHub Issues or Pull Requests GitHub Sponsors nuget NuGet Downloads GitHub Workflow Status (with event) GitHub last commit (branch) License

⚡ Why Choose TUnit?

Feature Traditional Frameworks TUnit
Test Discovery ❌ Runtime reflection Compile-time generation
Execution Speed ❌ Sequential by default Parallel by default
Modern .NET ⚠️ Limited AOT support 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


🏁 Quick Start

Using the Project Template (Recommended)

dotnet new install TUnit.Templates
dotnet new TUnit -n "MyTestProject"

Manual Installation

dotnet add package TUnit --prerelease

📖 📚 Complete Documentation & Guides - Everything you need to master TUnit

✨ Key Features

🚀 Performance & Modern Platform

  • 🔥 Source-generated tests (no reflection)
  • ⚡ Parallel execution by default
  • 🚀 Native AOT & trimming support
  • 📈 Optimized for performance

🎯 Advanced Test Control

  • 🔗 Test dependencies with [DependsOn]
  • 🎛️ Parallel limits & custom scheduling
  • 🛡️ Built-in analyzers & compile-time checks
  • 🎭 Custom attributes & extensible conditions

📊 Rich Data & Assertions

  • 📋 Multiple data sources ([Arguments], [Matrix], [ClassData])
  • ✅ Fluent async assertions
  • 🔄 Smart retry logic & conditional execution
  • 📝 Rich test metadata & context

🔧 Developer Experience

  • 💉 Full dependency injection support
  • 🪝 Comprehensive lifecycle hooks
  • 🎯 IDE integration (VS, Rider, VS Code)
  • 📚 Extensive documentation & examples

📝 Simple Test Example

[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]");
}

🎯 Data-Driven Testing

[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();
}

🔗 Advanced Test Orchestration

[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
}

🔧 Smart Test Control

// 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 });
}

🎯 Perfect For Every Testing Scenario

🧪 Unit Testing

[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

🔗 Integration Testing

[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

Load Testing

[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

🚀 What Makes TUnit Different?

Compile-Time Intelligence

Tests are discovered at build time, not runtime - enabling faster discovery, better IDE integration, and precise resource lifecycle management.

Parallel-First Architecture

Built for concurrency from day one with [DependsOn] for test chains, [ParallelLimit] for resource control, and intelligent scheduling.

Extensible by Design

The DataSourceGenerator<T> pattern and custom attribute system let you extend TUnit's capabilities without modifying core framework code.

🏆 Community & Ecosystem

🌟 Join thousands of developers modernizing their testing

Downloads Contributors Discussions

🤝 Active Community

🛠️ IDE Support

TUnit works seamlessly across all major .NET development environments:

Visual Studio (2022 17.13+)

Fully supported - No additional configuration needed for latest versions

⚙️ Earlier versions: Enable "Use testing platform server mode" in Tools > Manage Preview Features

JetBrains Rider

Fully supported

⚙️ Setup: Enable "Testing Platform support" in Settings > Build, Execution, Deployment > Unit Testing > VSTest

Visual Studio Code

Fully supported

⚙️ Setup: Install C# Dev Kit and enable "Use Testing Platform Protocol"

Command Line

Full CLI support - Works with dotnet test, dotnet run, and direct executable execution

📦 Package Options

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

🎯 Migration from Other Frameworks

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.

💡 Current Status

The API is mostly stable, but may have some changes based on feedback or issues before v1.0 release.


🚀 Ready to Experience the Future of .NET Testing?

Start in 30 Seconds

# 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

🎯 Why Wait? Join the Movement

📈 Performance

Optimized execution Parallel by default Zero reflection overhead

🔮 Future-Ready

Native AOT support Latest .NET features Source generation

🛠️ Developer Experience

Compile-time checks Rich IDE integration Intelligent debugging

🎭 Flexibility

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!

Performance Benchmark

Scenario: Building the test project

macos-latest


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 983.6 ms 21.02 ms 59.29 ms 958.3 ms
Build_NUnit 814.5 ms 15.05 ms 11.75 ms 815.0 ms
Build_xUnit 783.8 ms 12.93 ms 12.09 ms 783.0 ms
Build_MSTest 834.3 ms 9.31 ms 7.77 ms 834.4 ms

ubuntu-latest


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.958 s 0.0382 s 0.0628 s
Build_NUnit 1.491 s 0.0109 s 0.0091 s
Build_xUnit 1.489 s 0.0215 s 0.0191 s
Build_MSTest 1.515 s 0.0212 s 0.0188 s

windows-latest


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.964 s 0.0379 s 0.0579 s
Build_NUnit 1.547 s 0.0229 s 0.0203 s
Build_xUnit 1.539 s 0.0181 s 0.0161 s
Build_MSTest 1.575 s 0.0164 s 0.0153 s

Scenario: A single test that completes instantly (including spawning a new process and initialising the test framework)

macos-latest


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 66.87 ms 0.332 ms 0.278 ms
TUnit 476.81 ms 8.773 ms 8.207 ms
NUnit 703.58 ms 13.305 ms 13.663 ms
xUnit 718.01 ms 8.224 ms 7.290 ms
MSTest 616.90 ms 12.159 ms 12.486 ms

ubuntu-latest


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.89 ms 0.744 ms 2.182 ms
TUnit 813.30 ms 16.105 ms 20.368 ms
NUnit 1,278.67 ms 14.300 ms 13.376 ms
xUnit 1,337.63 ms 13.991 ms 13.087 ms
MSTest 1,128.92 ms 9.213 ms 8.167 ms

windows-latest


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
TUnit_AOT 54.36 ms 1.705 ms 5.026 ms
TUnit 903.08 ms 17.522 ms 25.129 ms
NUnit 1,368.83 ms 17.003 ms 15.073 ms
xUnit 1,422.16 ms 15.543 ms 14.539 ms
MSTest 1,220.54 ms 16.200 ms 15.153 ms

Scenario: A test that takes 50ms to execute, repeated 100 times (including spawning a new process and initialising the test framework)

macos-latest


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 244.0 ms 12.68 ms 37.40 ms
TUnit 629.5 ms 20.82 ms 61.37 ms
NUnit 14,006.8 ms 274.05 ms 494.17 ms
xUnit 14,383.5 ms 285.17 ms 514.22 ms
MSTest 14,103.8 ms 277.93 ms 494.01 ms

ubuntu-latest


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 74.03 ms 0.453 ms 0.445 ms
TUnit 898.20 ms 17.711 ms 25.401 ms
NUnit 6,278.11 ms 9.814 ms 9.180 ms
xUnit 6,441.39 ms 17.419 ms 16.293 ms
MSTest 6,263.40 ms 11.971 ms 11.198 ms

windows-latest


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 111.8 ms 2.21 ms 3.50 ms 109.4 ms
TUnit 950.6 ms 18.77 ms 25.06 ms 940.1 ms
NUnit 7,515.8 ms 27.67 ms 25.88 ms 7,515.9 ms
xUnit 7,588.5 ms 22.25 ms 20.81 ms 7,591.8 ms
MSTest 7,454.1 ms 22.62 ms 21.16 ms 7,453.2 ms