Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.
TUnit New Generation Testing Framework Introduction
Applicable Scenarios
This skill covers TUnit new-generation .NET testing framework introduction basics, from framework features to actual
project creation and test writing.
Core Topics
- TUnit framework features and design philosophy
- Source Generator driven test discovery
- AOT (Ahead-of-Time) compilation support
- Fluent async assertion system
- Project creation and package configuration
- Syntax differences compared to xUnit
TUnit Framework Core Features
1. Source Generator Driven Test Discovery
TUnit's biggest difference from traditional testing frameworks is using Source Generator to complete test discovery at
compile time:
Traditional Framework Approach (xUnit)
// xUnit discovers all methods through reflection at runtime
public class TraditionalTests
{
[Fact] // Only discovered at runtime
public void TestMethod() { }
}
```text
### TUnit's Innovative Approach
```csharp
// TUnit generates test registration code at compile time through Source Generator
public class ModernTests
{
[Test] // Processed and optimized at compile time
public async Task TestMethod()
{
await Assert.That(true).IsTrue();
}
}
```text
### Advantages
1. Avoid reflection cost: All test discovery completed at compile time
2. AOT compatible: Fully supports Native AOT compilation
3. Faster startup time: Especially in large test projects
### 2. AOT (Ahead-of-Time) Compilation Support
### JIT vs AOT Compilation Flow
```text
Traditional JIT: C# source → IL bytecode → JIT compile at runtime → machine code → execute
AOT: C# source → directly generate at compile time → machine code → execute directly
```text
### AOT Compilation Advantages
- Ultra-fast startup time (no waiting for JIT compilation)
- Smaller memory footprint
- Predictable performance
- More suitable for containerized deployment
### Enable AOT Support
```xml
<PropertyGroup>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
```text
### Actual Performance Differences
```text
Traditional JIT compilation test startup time: ~1-2 seconds
TUnit AOT compilation test startup time: ~50-100 milliseconds
(Large projects can achieve 10-30x startup time improvement)
```text
### 3. Microsoft.Testing.Platform Adoption
TUnit is built on Microsoft's latest Microsoft.Testing.Platform, not the traditional VSTest platform:
- Lighter test runner
- Better parallel control mechanism
- Native support for latest IDE integration
### Important Notes
TUnit projects **do not need** and **should not** install `Microsoft.NET.Test.Sdk` package.
### 4. Default Parallel Execution
TUnit sets parallel execution as default and provides fine-grained control:
```csharp
// Default all tests execute in parallel
[Test]
public async Task ParallelTest1() { }
[Test]
public async Task ParallelTest2() { }
// Can control parallel behavior when needed
[Test]
[NotInParallel("DatabaseTests")]
public async Task DatabaseTest() { }
```text
---
## TUnit Project Creation
### Method One: Manual Creation (Understanding Underlying Architecture)
```bash
# Create project directory
mkdir TUnitDemo
cd TUnitDemo
# Create solution
dotnet new sln -n MyApp
# Create main project
dotnet new classlib -n MyApp.Core -o src/MyApp.Core
# Create test project (use console template)
dotnet new console -n MyApp.Tests -o tests/MyApp.Tests
# Add to solution
dotnet sln add src/MyApp.Core/MyApp.Core.csproj
dotnet sln add tests/MyApp.Tests/MyApp.Tests.csproj
# Add project reference
dotnet add tests/MyApp.Tests/MyApp.Tests.csproj reference src/MyApp.Core/MyApp.Core.csproj
```text
### Method Two: Using TUnit Template (Recommended)
```bash
# Install TUnit project templates
dotnet new install TUnit.Templates
# Create test project using TUnit template
dotnet new tunit -n MyApp.Tests -o tests/MyApp.Tests
```text
### Test Project csproj Configuration
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<!-- TUnit core packages -->
<PackageReference Include="TUnit" Version="0.57.24" />
<!-- Code coverage support -->
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.4" />
<!-- TRX report support -->
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MyApp.Core\MyApp.Core.csproj" />
</ItemGroup>
</Project>
```text
### GlobalUsings Configuration
```csharp
// GlobalUsings.cs
global using TUnit.Core;
global using TUnit.Assertions;
global using MyApp.Core;
```text
---
## Async Test Methods (Required)
TUnit **requires all test methods to be async**, this is a framework technical requirement:
```csharp
// ❌ Error: won't compile
[Test]
public void WrongTest()
{
Assert.That(1 + 1).IsEqualTo(2);
}
// ✅ Correct: use async Task
[Test]
public async Task CorrectTest()
{
await Assert.That(1 + 1).IsEqualTo(2);
}
```text
---
## Test Attributes and Parameterization
### Basic Test [Test]
TUnit uniformly uses `[Test]` attribute, unlike xUnit which distinguishes `[Fact]` and `[Theory]`:
```csharp
// TUnit: uniformly use [Test]
[Test]
public async Task Add_Input1And2_ShouldReturn3()
{
var calculator = new Calculator();
var result = calculator.Add(1, 2);
await Assert.That(result).IsEqualTo(3);
}
```text
### Parameterized Tests [Arguments]
```csharp
// TUnit: use [Arguments] (equivalent to xUnit's [InlineData])
[Test]
[Arguments(1, 2, 3)]
[Arguments(-1, 1, 0)]
[Arguments(0, 0, 0)]
[Arguments(100, -50, 50)]
public async Task Add_MultipleInputs_ShouldReturnCorrectResult(int a, int b, int expected)
{
var calculator = new Calculator();
var result = calculator.Add(a, b);
await Assert.That(result).IsEqualTo(expected);
}
```text
---
## TUnit.Assertions Assertion System
TUnit adopts fluent assertion design, all assertions are async. Supports equality, boolean, numeric comparison, string, collection, exception, and other assertions, and can combine conditions through `And` / `Or`.
```csharp
// Basic usage examples
await Assert.That(actual).IsEqualTo(expected);
await Assert.That(email).Contains("@").And.EndsWith(".com");
await Assert.That(() => action()).Throws<InvalidOperationException>();
```text
> 📖 Complete assertion types and examples please refer to [TUnit Assertion System Detailed Description](references/tunit-assertions-detail.md)
---
## Test Lifecycle Management
TUnit supports constructor / `Dispose` pattern, and `[Before(Test)]`, `[Before(Class)]`, `[After(Test)]`, `[After(Class)]` and other attributes, providing more refined lifecycle control than xUnit.
```text
Execution order: Before(Class) → Constructor → Before(Test) → Test Method → After(Test) → Dispose → After(Class)
```text
> 📖 Complete lifecycle examples and attribute comparison table please refer to [Lifecycle Management Detailed Description](references/lifecycle-management.md)
---
## Parallel Execution Control
### NotInParallel Attribute
```csharp
// Default parallel execution
[Test]
public async Task ParallelTest1() { }
[Test]
public async Task ParallelTest2() { }
// Control specific tests not to run in parallel
[Test]
[NotInParallel("DatabaseTests")]
public async Task DatabaseTest1_NotInParallel()
{
// This test won't run in parallel with other "DatabaseTests" group
}
[Test]
[NotInParallel("DatabaseTests")]
public async Task DatabaseTest2_NotInParallel()
{
// Runs sequentially with DatabaseTest1
}
```text
---
## xUnit to TUnit Syntax Comparison
| Feature | xUnit | TUnit |
| ------- | ----- | ----- |
| **Basic Test** | `[Fact]` | `[Test]` |
| **Parameterized Test** | `[Theory]` + `[InlineData]` | `[Test]` + `[Arguments]` |
| **Basic Assertion** | `Assert.Equal(expected, actual)` | `await Assert.That(actual).IsEqualTo(expected)` |
| **Boolean Assertion** | `Assert.True(condition)` | `await Assert.That(condition).IsTrue()` |
| **Exception Test** | `Assert.Throws<T>(() => action())` | `await Assert.That(() => action()).Throws<T>()` |
| **Null Check** | `Assert.Null(value)` | `await Assert.That(value).IsNull()` |
| **String Check** | `Assert.Contains("text", fullString)` | `await Assert.That(fullString).Contains("text")` |
### Migration Example
### xUnit Original Code
```csharp
[Theory]
[InlineData("test@example.com", true)]
[InlineData("invalid", false)]
public void IsValidEmail_VariousInputs_ShouldReturnCorrectValidationResult(string email, bool expected)
{
var result = _validator.IsValidEmail(email);
Assert.Equal(expected, result);
}
```text
### TUnit Converted
```csharp
[Test]
[Arguments("test@example.com", true)]
[Arguments("invalid", false)]
public async Task IsValidEmail_VariousInputs_ShouldReturnCorrectValidationResult(string email, bool expected)
{
var result = _validator.IsValidEmail(email);
await Assert.That(result).IsEqualTo(expected);
}
```text
### Main Changes
1. `[Theory]` → `[Test]`
2. `[InlineData]` → `[Arguments]`
3. Method changed to `async Task`
4. All assertions prefixed with `await`
5. Fluent assertion syntax
---
## Execution and Debugging
### CLI Execution
```bash
# Build project
dotnet build
# Run all tests
dotnet test
# Verbose output
dotnet test --verbosity normal
# Generate coverage report
dotnet test --coverage
# Filter specific tests
dotnet test --filter "ClassName=CalculatorTests"
dotnet test --filter "TestName~Add"
```text
### AOT Compilation Execution
```bash
# Publish as AOT compiled version
dotnet publish -c Release -p:PublishAot=true
# Execute AOT compiled tests
.\bin\Release\net9.0\publish\MyApp.Tests.exe
```text
### IDE Integration
### Visual Studio 2022
- Version 17.13+ required
- Enable "Use testing platform server mode"
### VS Code
- Install C# Dev Kit extension
- Enable "Use Testing Platform Protocol"
### JetBrains Rider
- Enable "Testing Platform support"
---
## Performance Comparison
| Scenario | xUnit | TUnit | TUnit AOT | Performance Gain |
| -------- | ----- | ----- | --------- | ---------------- |
| **Simple Test Execution** | 1,400ms | 1,000ms | 60ms | 23x (AOT) |
| **Async Test** | 1,400ms | 930ms | 26ms | 54x (AOT) |
| **Parallel Test** | 1,425ms | 999ms | 54ms | 26x (AOT) |
---
## Common Issues and Solutions
### Issue 1: Package Compatibility
**Error:** Installed `Microsoft.NET.Test.Sdk` causing tests not discoverable
**Solution:** Remove `Microsoft.NET.Test.Sdk`, TUnit uses new testing platform
### Issue 2: IDE Integration Issues
**Symptom:** Tests not displaying or executing in IDE
### Solution
1. Confirm IDE version supports Microsoft.Testing.Platform
2. Enable relevant preview features
3. Reload project or restart IDE
### Issue 3: Async Assertion Forgotten
**Symptom:** Compilation errors or assertions not executing properly
**Solution:** All assertions need `await`, test methods must be `async Task`
---
## Applicable Scenario Assessment
### Suitable for TUnit
1. **New Projects**: No legacy baggage
2. **High Performance Requirements**: Large test suites (1000+ tests)
3. **Advanced Tech Stack**: Using .NET 8+, planning AOT adoption
4. **Heavy CI/CD Usage**: Test execution time directly impacts deployment frequency
5. **Containerized Deployment**: Fast startup time is important
### Not Recommended for Now
1. **Legacy Projects**: Already have large amounts of xUnit tests
2. **Conservative Teams**: Need stability over innovation
3. **Complex Test Ecosystem**: Heavy use of xUnit specific packages
4. **Old .NET Versions**: Still on .NET 6/7
---
## Reference Resources
### Original Articles
This skill content is distilled from the "Old School Software Engineer's Testing Practice - 30 Day Challenge" article series:
- **Day 28 - TUnit Introduction - Next Generation .NET Testing Framework Exploration**
- Article: https://ithelp.ithome.com.tw/articles/10377828
- Sample code: https://github.com/kevintsengtw/30Days_in_Testing_Samples/tree/main/day28
### Official Resources
- [TUnit Official Website](https://tunit.dev/)
- [TUnit GitHub](https://github.com/thomhurst/TUnit)
- [Migration from xUnit Guide](https://tunit.dev/docs/migration/xunit)
### Microsoft Official Documentation
- [Microsoft.Testing.Platform Introduction](https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-intro)
- [Native AOT Deployment](https://learn.microsoft.com/dotnet/core/deploying/native-aot)
1---2name: dotnet-testing-advanced-tunit-fundamentals-43description: Complete guide for TUnit new-generation testing framework. Use when creating test projects with TUnit or migrating from xUnit to TUnit. Covers Source Generator driven test discovery, AOT compilation support, fluent async assertions. Includes project creation, [Test] attribute, lifecycle management, parallel control, and xUnit syntax comparison. Keywords: TUnit, tunit testing, source generator testing, AOT testing, new generation testing framework, [Test], [Arguments], TUnit.Assertions, Assert.That, Before(Test), After(Test), NotInParallel, TUnit.Templates, Microsoft.Testing.Platform, TUnit vs xUnit, parallel execution4license: MIT5---67Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.89# TUnit New Generation Testing Framework Introduction1011## Applicable Scenarios1213This skill covers TUnit new-generation .NET testing framework introduction basics, from framework features to actual14project creation and test writing.1516### Core Topics1718- TUnit framework features and design philosophy19- Source Generator driven test discovery20- AOT (Ahead-of-Time) compilation support21- Fluent async assertion system22- Project creation and package configuration23- Syntax differences compared to xUnit2425---2627## TUnit Framework Core Features2829### 1. Source Generator Driven Test Discovery3031TUnit's biggest difference from traditional testing frameworks is using Source Generator to complete test discovery at32**compile time**:3334### Traditional Framework Approach (xUnit)3536````csharp37// xUnit discovers all methods through reflection at runtime38public class TraditionalTests39{40 [Fact] // Only discovered at runtime41 public void TestMethod() { }42}43```text4445### TUnit's Innovative Approach4647```csharp48// TUnit generates test registration code at compile time through Source Generator49public class ModernTests50{51 [Test] // Processed and optimized at compile time52 public async Task TestMethod()53 {54 await Assert.That(true).IsTrue();55 }56}57```text5859### Advantages60611. Avoid reflection cost: All test discovery completed at compile time622. AOT compatible: Fully supports Native AOT compilation633. Faster startup time: Especially in large test projects6465### 2. AOT (Ahead-of-Time) Compilation Support6667### JIT vs AOT Compilation Flow6869```text70Traditional JIT: C# source → IL bytecode → JIT compile at runtime → machine code → execute71AOT: C# source → directly generate at compile time → machine code → execute directly72```text7374### AOT Compilation Advantages7576- Ultra-fast startup time (no waiting for JIT compilation)77- Smaller memory footprint78- Predictable performance79- More suitable for containerized deployment8081### Enable AOT Support8283```xml84<PropertyGroup>85 <PublishAot>true</PublishAot>86 <InvariantGlobalization>true</InvariantGlobalization>87</PropertyGroup>88```text8990### Actual Performance Differences9192```text93Traditional JIT compilation test startup time: ~1-2 seconds94TUnit AOT compilation test startup time: ~50-100 milliseconds95(Large projects can achieve 10-30x startup time improvement)96```text9798### 3. Microsoft.Testing.Platform Adoption99100TUnit is built on Microsoft's latest Microsoft.Testing.Platform, not the traditional VSTest platform:101102- Lighter test runner103- Better parallel control mechanism104- Native support for latest IDE integration105106### Important Notes107108TUnit projects **do not need** and **should not** install `Microsoft.NET.Test.Sdk` package.109110### 4. Default Parallel Execution111112TUnit sets parallel execution as default and provides fine-grained control:113114```csharp115// Default all tests execute in parallel116[Test]117public async Task ParallelTest1() { }118119[Test]120public async Task ParallelTest2() { }121122// Can control parallel behavior when needed123[Test]124[NotInParallel("DatabaseTests")]125public async Task DatabaseTest() { }126```text127128---129130## TUnit Project Creation131132### Method One: Manual Creation (Understanding Underlying Architecture)133134```bash135# Create project directory136mkdir TUnitDemo137cd TUnitDemo138139# Create solution140dotnet new sln -n MyApp141142# Create main project143dotnet new classlib -n MyApp.Core -o src/MyApp.Core144145# Create test project (use console template)146dotnet new console -n MyApp.Tests -o tests/MyApp.Tests147148# Add to solution149dotnet sln add src/MyApp.Core/MyApp.Core.csproj150dotnet sln add tests/MyApp.Tests/MyApp.Tests.csproj151152# Add project reference153dotnet add tests/MyApp.Tests/MyApp.Tests.csproj reference src/MyApp.Core/MyApp.Core.csproj154```text155156### Method Two: Using TUnit Template (Recommended)157158```bash159# Install TUnit project templates160dotnet new install TUnit.Templates161162# Create test project using TUnit template163dotnet new tunit -n MyApp.Tests -o tests/MyApp.Tests164```text165166### Test Project csproj Configuration167168```xml169<Project Sdk="Microsoft.NET.Sdk">170171 <PropertyGroup>172 <TargetFramework>net9.0</TargetFramework>173 <ImplicitUsings>enable</ImplicitUsings>174 <Nullable>enable</Nullable>175 <IsPackable>false</IsPackable>176 <IsTestProject>true</IsTestProject>177 </PropertyGroup>178179 <ItemGroup>180 <!-- TUnit core packages -->181 <PackageReference Include="TUnit" Version="0.57.24" />182 <!-- Code coverage support -->183 <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.4" />184 <!-- TRX report support -->185 <PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.4.3" />186 </ItemGroup>187188 <ItemGroup>189 <ProjectReference Include="..\..\src\MyApp.Core\MyApp.Core.csproj" />190 </ItemGroup>191192</Project>193```text194195### GlobalUsings Configuration196197```csharp198// GlobalUsings.cs199global using TUnit.Core;200global using TUnit.Assertions;201global using MyApp.Core;202```text203204---205206## Async Test Methods (Required)207208TUnit **requires all test methods to be async**, this is a framework technical requirement:209210```csharp211// ❌ Error: won't compile212[Test]213public void WrongTest()214{215 Assert.That(1 + 1).IsEqualTo(2);216}217218// ✅ Correct: use async Task219[Test]220public async Task CorrectTest()221{222 await Assert.That(1 + 1).IsEqualTo(2);223}224```text225226---227228## Test Attributes and Parameterization229230### Basic Test [Test]231232TUnit uniformly uses `[Test]` attribute, unlike xUnit which distinguishes `[Fact]` and `[Theory]`:233234```csharp235// TUnit: uniformly use [Test]236[Test]237public async Task Add_Input1And2_ShouldReturn3()238{239 var calculator = new Calculator();240 var result = calculator.Add(1, 2);241 await Assert.That(result).IsEqualTo(3);242}243```text244245### Parameterized Tests [Arguments]246247```csharp248// TUnit: use [Arguments] (equivalent to xUnit's [InlineData])249[Test]250[Arguments(1, 2, 3)]251[Arguments(-1, 1, 0)]252[Arguments(0, 0, 0)]253[Arguments(100, -50, 50)]254public async Task Add_MultipleInputs_ShouldReturnCorrectResult(int a, int b, int expected)255{256 var calculator = new Calculator();257 var result = calculator.Add(a, b);258 await Assert.That(result).IsEqualTo(expected);259}260```text261262---263264## TUnit.Assertions Assertion System265266TUnit adopts fluent assertion design, all assertions are async. Supports equality, boolean, numeric comparison, string, collection, exception, and other assertions, and can combine conditions through `And` / `Or`.267268```csharp269// Basic usage examples270await Assert.That(actual).IsEqualTo(expected);271await Assert.That(email).Contains("@").And.EndsWith(".com");272await Assert.That(() => action()).Throws<InvalidOperationException>();273```text274275> 📖 Complete assertion types and examples please refer to [TUnit Assertion System Detailed Description](references/tunit-assertions-detail.md)276277---278279## Test Lifecycle Management280281TUnit supports constructor / `Dispose` pattern, and `[Before(Test)]`, `[Before(Class)]`, `[After(Test)]`, `[After(Class)]` and other attributes, providing more refined lifecycle control than xUnit.282283```text284Execution order: Before(Class) → Constructor → Before(Test) → Test Method → After(Test) → Dispose → After(Class)285```text286287> 📖 Complete lifecycle examples and attribute comparison table please refer to [Lifecycle Management Detailed Description](references/lifecycle-management.md)288289---290291## Parallel Execution Control292293### NotInParallel Attribute294295```csharp296// Default parallel execution297[Test]298public async Task ParallelTest1() { }299300[Test]301public async Task ParallelTest2() { }302303// Control specific tests not to run in parallel304[Test]305[NotInParallel("DatabaseTests")]306public async Task DatabaseTest1_NotInParallel()307{308 // This test won't run in parallel with other "DatabaseTests" group309}310311[Test]312[NotInParallel("DatabaseTests")]313public async Task DatabaseTest2_NotInParallel()314{315 // Runs sequentially with DatabaseTest1316}317```text318319---320321## xUnit to TUnit Syntax Comparison322323| Feature | xUnit | TUnit |324| ------- | ----- | ----- |325| **Basic Test** | `[Fact]` | `[Test]` |326| **Parameterized Test** | `[Theory]` + `[InlineData]` | `[Test]` + `[Arguments]` |327| **Basic Assertion** | `Assert.Equal(expected, actual)` | `await Assert.That(actual).IsEqualTo(expected)` |328| **Boolean Assertion** | `Assert.True(condition)` | `await Assert.That(condition).IsTrue()` |329| **Exception Test** | `Assert.Throws<T>(() => action())` | `await Assert.That(() => action()).Throws<T>()` |330| **Null Check** | `Assert.Null(value)` | `await Assert.That(value).IsNull()` |331| **String Check** | `Assert.Contains("text", fullString)` | `await Assert.That(fullString).Contains("text")` |332333### Migration Example334335### xUnit Original Code336337```csharp338[Theory]339[InlineData("test@example.com", true)]340[InlineData("invalid", false)]341public void IsValidEmail_VariousInputs_ShouldReturnCorrectValidationResult(string email, bool expected)342{343 var result = _validator.IsValidEmail(email);344 Assert.Equal(expected, result);345}346```text347348### TUnit Converted349350```csharp351[Test]352[Arguments("test@example.com", true)]353[Arguments("invalid", false)]354public async Task IsValidEmail_VariousInputs_ShouldReturnCorrectValidationResult(string email, bool expected)355{356 var result = _validator.IsValidEmail(email);357 await Assert.That(result).IsEqualTo(expected);358}359```text360361### Main Changes3623631. `[Theory]` → `[Test]`3642. `[InlineData]` → `[Arguments]`3653. Method changed to `async Task`3664. All assertions prefixed with `await`3675. Fluent assertion syntax368369---370371## Execution and Debugging372373### CLI Execution374375```bash376# Build project377dotnet build378379# Run all tests380dotnet test381382# Verbose output383dotnet test --verbosity normal384385# Generate coverage report386dotnet test --coverage387388# Filter specific tests389dotnet test --filter "ClassName=CalculatorTests"390dotnet test --filter "TestName~Add"391```text392393### AOT Compilation Execution394395```bash396# Publish as AOT compiled version397dotnet publish -c Release -p:PublishAot=true398399# Execute AOT compiled tests400.\bin\Release\net9.0\publish\MyApp.Tests.exe401```text402403### IDE Integration404405### Visual Studio 2022406407- Version 17.13+ required408- Enable "Use testing platform server mode"409410### VS Code411412- Install C# Dev Kit extension413- Enable "Use Testing Platform Protocol"414415### JetBrains Rider416417- Enable "Testing Platform support"418419---420421## Performance Comparison422423| Scenario | xUnit | TUnit | TUnit AOT | Performance Gain |424| -------- | ----- | ----- | --------- | ---------------- |425| **Simple Test Execution** | 1,400ms | 1,000ms | 60ms | 23x (AOT) |426| **Async Test** | 1,400ms | 930ms | 26ms | 54x (AOT) |427| **Parallel Test** | 1,425ms | 999ms | 54ms | 26x (AOT) |428429---430431## Common Issues and Solutions432433### Issue 1: Package Compatibility434435**Error:** Installed `Microsoft.NET.Test.Sdk` causing tests not discoverable436437**Solution:** Remove `Microsoft.NET.Test.Sdk`, TUnit uses new testing platform438439### Issue 2: IDE Integration Issues440441**Symptom:** Tests not displaying or executing in IDE442443### Solution4444451. Confirm IDE version supports Microsoft.Testing.Platform4462. Enable relevant preview features4473. Reload project or restart IDE448449### Issue 3: Async Assertion Forgotten450451**Symptom:** Compilation errors or assertions not executing properly452453**Solution:** All assertions need `await`, test methods must be `async Task`454455---456457## Applicable Scenario Assessment458459### Suitable for TUnit4604611. **New Projects**: No legacy baggage4622. **High Performance Requirements**: Large test suites (1000+ tests)4633. **Advanced Tech Stack**: Using .NET 8+, planning AOT adoption4644. **Heavy CI/CD Usage**: Test execution time directly impacts deployment frequency4655. **Containerized Deployment**: Fast startup time is important466467### Not Recommended for Now4684691. **Legacy Projects**: Already have large amounts of xUnit tests4702. **Conservative Teams**: Need stability over innovation4713. **Complex Test Ecosystem**: Heavy use of xUnit specific packages4724. **Old .NET Versions**: Still on .NET 6/7473474---475476## Reference Resources477478### Original Articles479480This skill content is distilled from the "Old School Software Engineer's Testing Practice - 30 Day Challenge" article series:481482- **Day 28 - TUnit Introduction - Next Generation .NET Testing Framework Exploration**483 - Article: https://ithelp.ithome.com.tw/articles/10377828484 - Sample code: https://github.com/kevintsengtw/30Days_in_Testing_Samples/tree/main/day28485486### Official Resources487488- [TUnit Official Website](https://tunit.dev/)489- [TUnit GitHub](https://github.com/thomhurst/TUnit)490- [Migration from xUnit Guide](https://tunit.dev/docs/migration/xunit)491492### Microsoft Official Documentation493494- [Microsoft.Testing.Platform Introduction](https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-intro)495- [Native AOT Deployment](https://learn.microsoft.com/dotnet/core/deploying/native-aot)496````