|
| 1 | +--- |
| 2 | +description: Write or troubleshoot tests using TUnit, TUnit.Assertions, or TUnit.Mocks, or migrate tests or mocks to TUnit or TUnit.Mocks. Routes to task-specific official documentation. Use only for tasks involving these packages or migration to them. |
| 3 | +license: MIT |
| 4 | +metadata: |
| 5 | + github-path: skills/tunit |
| 6 | + github-ref: refs/tags/v1.75.0 |
| 7 | + github-repo: https://github.com/thomhurst/TUnit |
| 8 | + github-tree-sha: 0d594ad16156140ff224e389ac441149d7259d62 |
| 9 | +name: tunit |
| 10 | +--- |
| 11 | +# TUnit |
| 12 | + |
| 13 | +Use this skill to find the TUnit guidance needed for the current task. Fetch documentation with an available web tool or HTTP client; network access is required. The documentation contains the API details and examples; do not load the whole site. |
| 14 | + |
| 15 | +## Load only what the task needs |
| 16 | + |
| 17 | +1. Check the relevant project files for TUnit package versions, target frameworks, and the SDK/test runner in `global.json`. Include centrally managed package versions when present. Preserve the project's versions unless an upgrade is requested or necessary and explained. |
| 18 | +2. Choose the closest topic below and fetch that Markdown page before choosing APIs or commands. Start with one page; fetch another only when the task needs it. Skip pages already available in the conversation unless they need refreshing. |
| 19 | +3. For an unlisted topic or a broken route, fetch [the documentation index](https://tunit.dev/llms.txt), search it for the feature or diagnostic, then fetch only the matching page. Do not fetch `llms-full.txt` or crawl every link. |
| 20 | +4. Follow related links only to resolve a specific gap. Prefer the `.md` version: remove a trailing slash and append `.md` to an HTML documentation path, before any fragment. Keep existing `.md` paths unchanged. Resolve relative links against the fetched page's URL. |
| 21 | +5. Apply the relevant example to the existing project and run a focused build or test when making code changes. Cite the documentation used. If current documentation differs from the installed API, check version-matched source or local API evidence before proposing an upgrade. If fetching fails, use available local documentation and state what could not be verified; do not guess APIs. |
| 22 | + |
| 23 | +## Topic routes |
| 24 | + |
| 25 | +Choose the link that matches the task; these are alternatives, not a reading checklist. |
| 26 | + |
| 27 | +| Task | Documentation | |
| 28 | +| --- | --- | |
| 29 | +| Create or configure a project | [Installation](https://tunit.dev/docs/getting-started/installation.md) | |
| 30 | +| Write a basic test | [First test](https://tunit.dev/docs/getting-started/writing-your-first-test.md) | |
| 31 | +| Assertions, exceptions, or assertion composition | [Assertions](https://tunit.dev/docs/assertions/getting-started.md) | |
| 32 | +| Parameterized tests | [Arguments](https://tunit.dev/docs/writing-tests/arguments.md), [method data](https://tunit.dev/docs/writing-tests/method-data-source.md), or [matrix data](https://tunit.dev/docs/writing-tests/matrix-tests.md) | |
| 33 | +| Setup, teardown, or hooks | [Lifecycle](https://tunit.dev/docs/writing-tests/lifecycle.md) | |
| 34 | +| Fixtures, shared resources, or dependency injection | [Class data sources](https://tunit.dev/docs/writing-tests/class-data-source.md) or [dependency injection](https://tunit.dev/docs/writing-tests/dependency-injection.md) | |
| 35 | +| Concurrency or dependencies between tests | [Parallelism](https://tunit.dev/docs/execution/parallelism.md) or [ordering](https://tunit.dev/docs/writing-tests/ordering.md) | |
| 36 | +| Run tests or select tests | [Running tests](https://tunit.dev/docs/getting-started/running-your-tests.md) or [filters](https://tunit.dev/docs/execution/test-filters.md) | |
| 37 | +| Migrate an existing suite | [xUnit](https://tunit.dev/docs/migration/xunit.md), [NUnit](https://tunit.dev/docs/migration/nunit.md), or [MSTest](https://tunit.dev/docs/migration/mstest.md), matching the source framework | |
| 38 | +| Mocking | [TUnit.Mocks](https://tunit.dev/docs/writing-tests/mocking.md) | |
| 39 | +| Migrate mocks to TUnit.Mocks | [Moq](https://tunit.dev/docs/migration/mocking/moq.md), [NSubstitute](https://tunit.dev/docs/migration/mocking/nsubstitute.md), or [FakeItEasy](https://tunit.dev/docs/migration/mocking/fakeiteasy.md), matching the source library | |
| 40 | +| Aspire integration testing | [Aspire](https://tunit.dev/docs/examples/aspire.md) | |
| 41 | +| ASP.NET Core integration testing | [ASP.NET Core](https://tunit.dev/docs/examples/aspnet.md) | |
| 42 | +| Playwright browser testing | [Playwright](https://tunit.dev/docs/examples/playwright.md) | |
| 43 | +| Testcontainers and container fixtures | [ASP.NET Core integration examples](https://tunit.dev/docs/examples/aspnet.md) (see "With Testcontainers") | |
| 44 | +| Native AOT, trimming, or reflection mode | [AOT compatibility](https://tunit.dev/docs/writing-tests/aot.md) or [engine modes](https://tunit.dev/docs/execution/engine-modes.md) | |
| 45 | +| Custom assertions | [Assertion source generators](https://tunit.dev/docs/assertions/extensibility/source-generator-assertions.md) or [custom assertion implementations](https://tunit.dev/docs/assertions/extensibility/custom-assertions.md) | |
| 46 | +| Custom data sources | [Data source generators](https://tunit.dev/docs/extending/data-source-generators.md) | |
| 47 | +| Event receivers | [Event subscribing](https://tunit.dev/docs/writing-tests/event-subscribing.md) | |
| 48 | +| TestContext and test metadata | [Test context](https://tunit.dev/docs/writing-tests/test-context.md) | |
| 49 | +| Diagnostics, output, or tracing | [Logging](https://tunit.dev/docs/extending/logging.md), [test artifacts](https://tunit.dev/docs/writing-tests/artifacts.md), or [OpenTelemetry](https://tunit.dev/docs/examples/opentelemetry.md) | |
| 50 | +| Cancellation | [Cancelling a test](https://tunit.dev/docs/execution/cancellation.md) | |
| 51 | +| Discovery, build, or execution failures | [Troubleshooting](https://tunit.dev/docs/troubleshooting.md) | |
| 52 | + |
| 53 | +For other topics, such as analyzers or framework-specific integrations, use the index selectively. |
| 54 | + |
| 55 | +## Essential distinctions |
| 56 | + |
| 57 | +- Await TUnit assertions, for example `await Assert.That(actual).IsEqualTo(expected);`. |
| 58 | +- Tests run in parallel by default. Account for shared mutable state and resource lifetimes. |
| 59 | +- TUnit uses Microsoft.Testing.Platform and `--treenode-filter`. Match command syntax to the project's SDK and runner mode; do not substitute VSTest `--filter` or assume every `dotnet test` invocation needs a `--` separator. |
| 60 | +- Source-generated discovery is the default; reflection mode also exists. Check the relevant documentation when changing discovery or Native AOT behavior. |
| 61 | +- TUnit.Assertions and TUnit.Mocks also work with other test frameworks. Using them alone does not require changing the project's test runner. |
0 commit comments