Guidance for the TUnit testing framework in .NET, focusing on async assertions and test organization.
Install
mkdir -p .claude/skills/tunit && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13421" && unzip -o skill.zip -d .claude/skills/tunit && rm skill.zipInstalls to .claude/skills/tunit
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Use this skill to write, review, and fix TUnit tests in .NET projects: for new test classes, assertions, data-driven tests, lifecycle hooks, debugging, migrating from xUnit/NUnit, choosing assertions, using Bogus, NSubstitute mocks, integration tests, or questions about parallelism and test ordering; prefer this skill over guessing, as TUnit's async-first API has non-obvious patterns differing from xUnit/NUnit.Key capabilities
- →Write new TUnit test classes
- →Use async-first assertions in TUnit
- →Implement data-driven tests with Arguments, MethodDataSource, ClassDataSource
- →Utilize lifecycle hooks (Before/After) and attributes (Category, Retry, Repeat)
- →Debug common TUnit mistakes like silently skipped assertions
- →Migrate existing tests from xUnit/NUnit to TUnit
How it works
The skill provides guidance and best practices for writing, reviewing, and fixing TUnit tests, emphasizing its async-first API, assertion patterns, data-driven testing, and lifecycle hooks.
Inputs & outputs
When to use tunit
- →Writing TUnit test classes
- →Migrating from xUnit or NUnit
- →Creating data-driven tests
- →Debugging failing tests
About this skill
TUnit Testing Skill
TUnit is a modern .NET testing framework that is async-first, source-generated, and runs on Microsoft.Testing.Platform.
Quick-start anatomy
public class OrderHandlerTests
{
[Test]
[Category("Unit")] // categorise for filtering
public async Task PlaceOrder_Valid_ReturnsOk()
{
// Arrange …
// Act …
// Assert — always await the assertion
await Assert.That(result).IsNotNull();
await Assert.That(result.Status).IsEqualTo("Confirmed");
}
}
Key rule: every assertion line must be await-ed. Forgetting the await
silently skips the assertion.
Reference files — read before writing code
| Topic | File |
|---|---|
| Assertion API (equality, nulls, booleans, collections, strings, exceptions, multiple) | references/assertions.md |
| All attributes (Test, Category, Arguments, Before/After, Retry, Repeat, NotInParallel…) | references/attributes.md |
| Data-driven tests (Arguments, MethodDataSource, ClassDataSource) | references/data-driven.md |
| Integration test patterns (Aspire, test infrastructure, async helpers) | references/integration-patterns.md |
Core rules
✅ [Test] async Task ❌ [Fact] / [TestMethod] / [TestCase]
✅ await Assert.That(...) ❌ Assert.Equal / FluentAssertions
✅ Per-test data creation ❌ shared mutable state between tests
Running tests
dotnet test # all projects (parallel)
dotnet test -- --maximum-parallel-tests 4 # cap parallelism
dotnet test -- --treenode-filter "/*/*/*/*[Category=Unit]" # filter by category
dotnet test --project tests/MyProject.Tests/MyProject.Tests.csproj
Common mistakes & fixes
| Mistake | Fix |
|---|---|
| Assertion silently skipped | Add await to every Assert.That(…) call |
| Tests interfere with each other | Create all test data inside each test; never share mutable fields |
| Polling for eventual consistency | Use condition helpers or WaitForConditionAsync patterns; never Task.Delay |
Assert.Fail not reached after exception | Use Assert.That(…).Throws<T>() pattern instead of try/catch |
Missing [Before(Class)] / [After(Class)] | Hooks must be public static async Task; see attributes reference |
| Data-driven test parameters don't compile | Types in [Arguments] must exactly match method parameter types |
When not to use it
- →When using xUnit or NUnit frameworks exclusively
- →When shared mutable state between tests is desired
- →When `Task.Delay` is used for polling eventual consistency
Limitations
- →Every assertion line must be `await`-ed to prevent silent skipping.
- →All test data must be created inside each test; no shared mutable fields.
- →Polling for eventual consistency should use condition helpers, not `Task.Delay`.
How it compares
This skill focuses on the TUnit framework's async-first API and specific patterns, which differ from xUnit/NUnit, providing tailored guidance for its unique features.
Compared to similar skills
tunit side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| tunit (this skill) | 0 | 4mo | Review | Intermediate |
| csharp-pro | 9 | 4mo | No flags | Intermediate |
| performance-benchmark | 3 | 4mo | No flags | Intermediate |
| run-device-tests | 3 | 2mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by aalmada
View all by aalmada →You might also like
csharp-pro
sickn33
Write modern C# code with advanced features like records, pattern matching, and async/await. Optimizes .NET applications, implements enterprise patterns, and ensures comprehensive testing. Use PROACTIVELY for C# refactoring, performance optimization, or complex .NET solutions.
performance-benchmark
dotnet
Generate and run ad hoc performance benchmarks to validate code changes. Use this when asked to benchmark, profile, or validate the performance impact of a code change in dotnet/runtime.
run-device-tests
dotnet
Build and run .NET MAUI device tests locally with category filtering. Supports iOS, MacCatalyst, Android on macOS; Android, Windows on Windows. Use TestFilter to run specific test categories.
backend-testing
exceptionless
Backend testing with xUnit, Foundatio.Xunit, integration tests with AppWebHostFactory, FluentClient, ProxyTimeProvider for time manipulation, and test data builders. Keywords: xUnit, Fact, Theory, integration tests, AppWebHostFactory, FluentClient, ProxyTimeProvider, TimeProvider, Foundatio.Xunit, TestWithLoggingBase, test data builders
bunit-test-migration
FritzAndFriends
Migrate bUnit test files from deprecated beta API (1.0.0-beta-10) to bUnit 2.x stable API. Use this when working on .razor test files in BlazorWebFormsComponents.Test that contain old patterns like TestComponentBase, Fixture, or SnapshotTest.
deployment-e2e-testing
dotnet
Guide for writing Aspire deployment end-to-end tests. Use this when asked to create, modify, or debug deployment E2E tests that deploy to Azure.