dotnet-testing-advanced-tunit-advanced_skill

This skill enables advanced TUnit testing with data-driven, dependency injection, and integration testing techniques to boost reliability and coverage.
  • C#

19

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-advanced-tunit-advanced

  • SKILL.md15.2 KB

Overview

This skill is a practical guide to advanced TUnit usage for data-driven tests, dependency injection, execution control, and ASP.NET Core integration testing. It consolidates patterns for MethodDataSource, ClassDataSource, Matrix Tests, properties-based filtering, Retry/Timeout controls, WebApplicationFactory integration, and Testcontainers orchestration. Use it to standardize test design, improve reliability, and scale integration scenarios.

How this skill works

The skill explains how TUnit discovers and runs tests (Source Generation and Reflection modes) and how to provide test data via MethodDataSource, ClassDataSource, and MatrixDataSource. It shows how to inject services using a MicrosoftDependencyInjectionDataSourceAttribute, manage lifecycles with Before/After hooks, and control execution with Retry, Timeout, and DisplayName attributes. It also covers spinning up WebApplicationFactory-based API tests and coordinating multi-container environments with Testcontainers at assembly scope.

When to use it

  • When you need flexible, reusable data-driven tests that pull data from methods, classes, or matrix combinations.
  • When tests require automatic DI to mirror production services or to simplify setup and teardown.
  • When you must filter large suites by Category, Priority, Environment, or custom properties.
  • When integration tests need a real ASP.NET Core host via WebApplicationFactory.
  • When complex multi-service infrastructures (Postgres, Redis, Kafka) require container orchestration for tests.
  • When execution stability needs Retry/Timeout controls and readable DisplayName reports.

Best practices

  • Define centralized property constants (Category, Priority, Environment) to ensure consistent filtering and readable reports.
  • Use DI via a shared ServiceProvider configured once to minimize duplication and manage scopes per test.
  • Limit Retry to external-flaky dependencies; use Timeout with realistic SLAs and Stopwatch verification.
  • Start containers once at assembly level with Before(Assembly)/After(Assembly) and reuse network to speed tests and isolate state.
  • Use SourceGenerated mode for speed and type-safety; fall back to Reflection mode for dynamic discovery scenarios.

Example use cases

  • Run business-rule matrix tests for combinations of customer tiers and discount rules using MatrixDataSource.
  • Inject a mocked OrderService and repositories via MicrosoftDependencyInjectionDataSource for concise unit-style integration tests.
  • Filter and run only high-priority unit tests in CI using dotnet run --treenode-filter with Category and Priority properties.
  • Execute full API contract tests against a real host using WebApplicationFactory<Program> with HttpClient assertions and content-type checks.
  • Bring up PostgreSQL and Kafka with Testcontainers in Before(Assembly) to run end-to-end scenarios that require multiple services.

FAQ

Keep parameter sets small, prune irrelevant combinations, or prefer targeted MethodDataSource or ClassDataSource when many permutations are unnecessary.

When should I use SourceGenerated vs Reflection engine mode?

Use SourceGenerated for performance, type safety, and AOT compatibility. Use Reflection for dynamic discovery needs or mixed-language projects.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
dotnet-testing-advanced-tunit-advanced skill by kevintsengtw/dotnet-testing-agent-skills | VeilStrat