Csharp Tunit
GitHubOfficialOriginally contributed by @michaelvolz as prompts/csharp-tunit.prompt.md; moved into a skill by pull request #761Distributed by GitHub
- Skill
- Guidelines
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured reference for implementing unit tests with TUnit. It covers project configuration, the Arrange-Act-Assert pattern, lifecycle management, and advanced features like data-driven testing and parallel execution. It also serves as a migration guide for developers transitioning from xUnit to TUnit, highlighting the framework's modern fluent assertion syntax and asynchronous testing capabilities.
What it does
- Outlines standard project structure and naming conventions for TUnit tests
- Explains the use of lifecycle hooks for setup and teardown operations
- Details the implementation of data-driven tests using attributes like Arguments and MethodData
- Provides a reference for TUnit's fluent, asynchronous assertion syntax
- Describes advanced features including test dependencies, retries, and parallel execution control
- Offers a mapping guide for migrating existing test suites from xUnit to TUnit
When to use it
- When starting a new .NET 8.0 or higher project and choosing a testing framework
- When you need to implement complex data-driven testing scenarios
- When migrating an existing test suite from xUnit to TUnit
- When you require fine-grained control over test parallelization and execution limits
- When you want to utilize modern, fluent, and asynchronous assertion patterns
Advantages
- Provides clear, actionable patterns for consistent test organization
- Simplifies the transition from legacy frameworks with direct migration mappings
- Enables more expressive and readable test code through fluent assertions
- Offers advanced lifecycle management for complex test scenarios
- Supports modern .NET development practices with built-in parallel execution
Usage examples
- “How do I write a data-driven test in TUnit?”
- The agent explains using the [Test] attribute combined with [Arguments] for inline data or [MethodData] for external data sources.
- “What is the TUnit equivalent of xUnit's Assert.Equal?”
- The agent provides the TUnit syntax: await Assert.That(actual).IsEqualTo(expected).
- “How can I run tests in parallel in TUnit?”
- The agent explains that TUnit runs tests in parallel by default and shows how to use [ParallelLimit] or [NotInParallel] to manage concurrency.
- “How do I handle setup and teardown in TUnit?”
- The agent describes using lifecycle hooks like [Before(Test)] and [After(Test)] instead of constructors or IDisposable.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/github/csharp-tunit/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip csharp-tunit.zip -d .agents/skills
Documentation by michaelvolz
TUnit Best Practices
Your goal is to help me write effective unit tests with TUnit, covering both standard and data-driven testing approaches.
Project Setup
Use a separate test project with naming convention
[ProjectName].TestsReference TUnit package and TUnit.Assertions for fluent assertions
Create test classes that match the classes being tested (e.g.,
CalculatorTestsforCalculator)Use .NET SDK test commands:
dotnet testfor running testsTUnit requires .NET 8.0 or higher
Test Structure
No test class attributes required (like xUnit/NUnit)
Use
[Test]attribute for test methods (not[Fact]like xUnit)Follow the Arrange-Act-Assert (AAA) pattern
Name tests using the pattern
MethodName_Scenario_ExpectedBehaviorUse lifecycle hooks:
[Before(Test)]for setup and[After(Test)]for teardownUse
[Before(Class)]and[After(Class)]for shared context between tests in a classUse
[Before(Assembly)]and[After(Assembly)]for shared context across test classesTUnit supports advanced lifecycle hooks like
[Before(TestSession)]and[After(TestSession)]
Standard Tests
Keep tests focused on a single behavior
Avoid testing multiple behaviors in one test method
Use TUnit's fluent assertion syntax with
await Assert.That()Include only the assertions needed to verify the test case
Make tests independent and idempotent (can run in any order)
Avoid test interdependencies (use
[DependsOn]attribute if needed)
Data-Driven Tests
Use
[Arguments]attribute for inline test data (equivalent to xUnit's[InlineData])Use
[MethodData]for method-based test data (equivalent to xUnit's[MemberData])Use
[ClassData]for class-based test dataCreate custom data sources by implementing
ITestDataSourceUse meaningful parameter names in data-driven tests
Multiple
[Arguments]attributes can be applied to the same test method
Assertions
Use
await Assert.That(value).IsEqualTo(expected)for value equalityUse
await Assert.That(value).IsSameReferenceAs(expected)for reference equalityUse
await Assert.That(value).IsTrue()orawait Assert.That(value).IsFalse()for boolean conditionsUse
await Assert.That(collection).Contains(item)orawait Assert.That(collection).DoesNotContain(item)for collectionsUse
await Assert.That(value).Matches(pattern)for regex pattern matchingUse
await Assert.That(action).Throws<TException>()orawait Assert.That(asyncAction).ThrowsAsync<TException>()to test exceptionsChain assertions with
.Andoperator:await Assert.That(value).IsNotNull().And.IsEqualTo(expected)Use
.Oroperator for alternative conditions:await Assert.That(value).IsEqualTo(1).Or.IsEqualTo(2)Use
.Within(tolerance)for DateTime and numeric comparisons with toleranceAll assertions are asynchronous and must be awaited
Advanced Features
Use
[Repeat(n)]to repeat tests multiple timesUse
[Retry(n)]for automatic retry on failureUse
[ParallelLimit<T>]to control parallel execution limitsUse
[Skip("reason")]to skip tests conditionallyUse
[DependsOn(nameof(OtherTest))]to create test dependenciesUse
[Timeout(milliseconds)]to set test timeoutsCreate custom attributes by extending TUnit's base attributes
Test Organization
Group tests by feature or component
Use
[Category("CategoryName")]for test categorizationUse
[DisplayName("Custom Test Name")]for custom test namesConsider using
TestContextfor test diagnostics and informationUse conditional attributes like custom
[WindowsOnly]for platform-specific tests
Performance and Parallel Execution
TUnit runs tests in parallel by default (unlike xUnit which requires explicit configuration)
Use
[NotInParallel]to disable parallel execution for specific testsUse
[ParallelLimit<T>]with custom limit classes to control concurrencyTests within the same class run sequentially by default
Use
[Repeat(n)]with[ParallelLimit<T>]for load testing scenarios
Migration from xUnit
Replace
[Fact]with[Test]Replace
[Theory]with[Test]and use[Arguments]for dataReplace
[InlineData]with[Arguments]Replace
[MemberData]with[MethodData]Replace
Assert.Equalwithawait Assert.That(actual).IsEqualTo(expected)Replace
Assert.Truewithawait Assert.That(condition).IsTrue()Replace
Assert.Throws<T>withawait Assert.That(action).Throws<T>()Replace constructor/IDisposable with
[Before(Test)]/[After(Test)]Replace
IClassFixture<T>with[Before(Class)]/[After(Class)]
Why TUnit over xUnit?
TUnit offers a modern, fast, and flexible testing experience with advanced features not present in xUnit, such as asynchronous assertions, more refined lifecycle hooks, and improved data-driven testing capabilities. TUnit's fluent assertions provide clearer and more expressive test validation, making it especially suitable for complex .NET projects.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.1 KiB
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md5.0 KiB
Requirements and compatibility
Written for: GitHub Copilot
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Originally contributed by
@michaelvolzas prompts/csharp-tunit.prompt.mdmoved into a skill by pull request #761
- Publisher
- GitHub (Official)
- Distributed by
- GitHub
- Source
- github/awesome-copilot · skills/csharp-tunit · commit 797337f
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Contributors
- CypherHK, derekclair, michaelvolz
AutoGineer is not affiliated with or endorsed by michaelvolz or GitHub.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download csharp-tunit.zip