| name | dotnet-testing-advanced-tunit-advanced |
| description | Complete guide for TUnit advanced applications. Use when using TUnit for data-driven testing, dependency injection, or integration testing. Covers MethodDataSource, ClassDataSource, Matrix Tests, Properties filtering. Includes Retry/Timeout control, WebApplicationFactory integration, Testcontainers multi-service orchestration.
Keywords: TUnit advanced, TUnit advanced, MethodDataSource, ClassDataSource, Matrix Tests, MatrixDataSource, MicrosoftDependencyInjectionDataSource, Property, Retry, Timeout, data-driven testing, test filtering, WebApplicationFactory TUnit, multi-container orchestration
|
| metadata | {"short-description":".NET skill guidance for dotnet-testing-advanced-tunit-advanced"} |
Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.
TUnit Advanced Applications: Data-Driven Testing, Dependency Injection, and Integration Testing
Applicable Scenarios
This skill covers TUnit advanced application techniques, from data-driven testing to dependency injection, from
execution control to ASP.NET Core integration testing practice.
Core Topics
- Data-driven testing advanced techniques (MethodDataSource, ClassDataSource, Matrix Tests)
- Properties attribute marking and test filtering
- Test lifecycle and dependency injection
- Execution control (Retry, Timeout, DisplayName)
- ASP.NET Core integration testing (WebApplicationFactory)
- Performance testing and load testing
- TUnit + Testcontainers complex infrastructure orchestration
- TUnit Engine Modes and troubleshooting
Data-Driven Testing Advanced Techniques
TUnit provides MethodDataSource, ClassDataSource, and Matrix Tests as three advanced data sources. MethodDataSource is
most flexible, supporting dynamic generation and external file loading; ClassDataSource is suitable for cross-test class
data sharing and AutoFixture integration; Matrix Tests automatically generates all parameter combinations (note: control
quantity to avoid explosive growth).
Full examples and comparison table please refer to
references/data-driven-testing.md
Properties Attribute Marking and Test Filtering
Basic Properties Usage
[Test]
[Property("Category", "Database")]
[Property("Priority", "High")]
public async Task DatabaseTest_HighPriority_ShouldBeFilterableByAttribute()
{
await Assert.That(true).IsTrue();
}
[Test]
[Property("Category", "Unit")]
[Property("Priority", "Medium")]
public async Task UnitTest_MediumPriority_BasicValidation()
{
await Assert.That(1 + 1).IsEqualTo(2);
}
[Test]
[Property("Category", "Integration")]
[Property("Priority", "Low")]
[Property("Environment", "Development")]
public async Task IntegrationTest_LowPriority_OnlyRunInDevEnvironment()
{
await Assert.That("Hello World").Contains("World");
}
```text
### Establishing Consistent Attribute Naming Conventions
```csharp
public static class TestProperties
{
public const CATEGORY_UNIT = ;
CATEGORY_INTEGRATION = ;
CATEGORY_E2E = ;
PRIORITY_CRITICAL = ;
PRIORITY_HIGH = ;
PRIORITY_MEDIUM = ;
PRIORITY_LOW = ;
ENV_DEVELOPMENT = ;
ENV_STAGING = ;
ENV_PRODUCTION = ;
}
[]
[]
[]
{
Assert.That( + ).IsEqualTo();
}
```text
TUnit uses `dotnet run` instead of `dotnet test`:
```bash
dotnet run --treenode-filter
dotnet run --treenode-filter
dotnet run --treenode-filter
dotnet run --treenode-filter
dotnet run --treenode-filter
```text
- Path pattern `*