/csharp-dotnet-development:csharp-xunitfrom csharp-dotnet-development
Applies xUnit best practices for C# unit tests including test project setup, Fact/Theory structure, data-driven tests, assertions, fixtures, mocking, and dotnet test execution.
Ships in csharp-dotnet-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guide C# test design by turning a class, behavior, or test request into focused xUnit tests that use idiomatic setup, data sources, assertions, isolation, and dotnet test validation.
[Theory] and [InlineData]."| Concern | Rule |
|---|---|
| Test project | Use a separate [ProjectName].Tests project. |
| Packages | Reference Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio. |
| Test class names | Match the class under test, for example CalculatorTests for Calculator. |
| Command | Run tests with dotnet test; narrow with --filter for targeted validation. |
| Visibility | Prefer testing public behavior; use InternalsVisibleTo only when the project already exposes internals for tests. |
| Pattern | Use it for | Notes |
|---|---|---|
[Fact] | One fact-based scenario with no external data rows. | No class-level test attribute is required in xUnit, unlike MSTest/NUnit. |
[Theory] | Same behavior over multiple inputs. | Pair with one data source attribute. |
| Arrange-Act-Assert | Every test body. | Keep setup, action, and assertions visually separable. |
MethodName_Scenario_ExpectedBehavior | Test method naming. | Example: Divide_ByZero_ThrowsDivideByZeroException. |
| Constructor | Per-test setup. | xUnit creates a new test class instance for each test. |
IDisposable.Dispose() | Per-test teardown. | Release files, handles, or mocks that require cleanup. |
IAsyncLifetime | Async setup or teardown. | Use InitializeAsync and DisposeAsync instead of blocking on tasks. |
| Source | Best use | Example shape |
|---|---|---|
[InlineData] | Small scalar cases that fit on one line. | [InlineData(2, 3, 5)] |
[MemberData] | Generated, named, reusable, or method-based test data. | Static property or method returning IEnumerable<object[]>. |
[ClassData] | Larger reusable or class-based datasets. | Class implements IEnumerable<object[]>. |
Custom DataAttribute | Dynamic or domain-specific data creation. | Keep deterministic; avoid network calls and current time. |
Use meaningful parameter names. Keep the assertion intent identical across all rows; split into separate theories when rows prove different behaviors.
| Need | Assertion |
|---|---|
| Value equality | Assert.Equal(expected, actual); baseline form Assert.Equal. |
| Reference identity | Assert.Same(expected, actual); baseline form Assert.Same. |
| Boolean | Assert.True(condition) or Assert.False(condition) with a clear message when helpful; baseline forms Assert.True and Assert.False. |
| Collections | Assert.Contains, Assert.DoesNotContain, Assert.Collection, or Assert.All. |
| Regex | Assert.Matches or Assert.DoesNotMatch. |
| Exceptions | Assert.Throws<T> or await Assert.ThrowsAsync<T>. |
| Readability | Use a fluent assertions library only if the project already uses one or accepts the dependency. |
| Technique | Use when | Avoid |
|---|---|---|
IClassFixture<T> | Expensive context shared by tests in one class. | Storing mutable state that leaks between tests. |
ICollectionFixture<T> | Shared context across multiple test classes. | Using it as a global singleton for unrelated tests. |
| Moq or NSubstitute | Isolate dependencies behind interfaces. | Mocking the class under test or framework primitives unnecessarily. |
| DI container | Complex object graphs already use dependency injection. | Rebuilding the production container when a direct constructor call is clearer. |
[Trait("Category", "CategoryName")] | Filtering smoke, integration, or slow tests. | Encoding ordering dependencies as categories. |
ITestOutputHelper | Diagnostics that should appear only on failure or in test output. | Replacing assertions with log inspection. |
Skip = "reason" | Temporarily disabled tests with a specific reason in fact/theory attributes. | Silent or permanent skips. |
[InlineData] usually belong in [MemberData] or builders.## xUnit test plan
**Target:** `<class or behavior>`
**Command:** `dotnet test <project-or-solution> --filter <optional-filter>`
| Test | Attribute | Data source | Behavior verified |
| --- | --- | --- | --- |
| `<MethodName_Scenario_ExpectedBehavior>` | `[Fact]` or `[Theory]` | `<none / InlineData / MemberData / ClassData>` | `<single behavior>` |
### Notes
- Fixtures: `<IClassFixture<T> / ICollectionFixture<T> / none>`
- Assertions: `<key Assert.* calls>`
- Isolation: `<mocks, fakes, or real collaborators>`
[Fact] for single cases and [Theory] with data attributes for data-driven cases.MethodName_Scenario_ExpectedBehavior or the project's established equivalent.IDisposable.Dispose(), IClassFixture<T>, or ICollectionFixture<T> appropriately.Assert.* API and cover exception paths with Assert.Throws<T> or Assert.ThrowsAsync<T>.dotnet test.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin csharp-dotnet-development9 skills in this plugin
/aspnet-minimal-api-openapiCreate or review ASP.NET Minimal API endpoints with typed results, DTO validation, endpoint groups, filters, ProblemDetails, and OpenAPI documentation. Use this skill when asked to add Minimal APIs, document endpoints with Swagger/OpenAPI, use .NET 9 built-in OpenAPI, or design request and response types./csharp-asyncReview, design, and fix C# async code using Task, Task<T>, ValueTask<T>, cancellation, ConfigureAwait, async streams, and TAP conventions. Use when the user asks for C# async best practices, deadlock fixes, async method naming, parallel awaits, or replacing .Wait(), .Result, and async void./csharp-mstestApply modern MSTest 3.x/4.x testing practices for C# projects. Use when asked to write or review MSTest unit tests, choose assertion APIs, convert ExpectedException tests, design data-driven tests, use TestContext, configure lifecycle hooks, add categories or work items, or run dotnet test for MSTest./csharp-nunitDesign, write, and review NUnit tests for .NET projects, including standard tests, data-driven tests, assertions, setup/teardown, categories, and isolation with mocks. Use this skill when the user asks for NUnit best practices, `dotnet test`, `[TestCase]`, `[TestCaseSource]`, or C# unit test structure./csharp-tunitWrite, review, or migrate C# unit tests using TUnit. Use when the user asks for TUnit best practices, .NET test project setup, TUnit assertions, lifecycle hooks, data-driven tests, parallel execution, retries, categories, or xUnit-to-TUnit migration./dotnet-best-practicesReview or improve .NET and C# code against solution/project best practices for documentation, architecture, dependency injection, resources, async, tests, configuration, Semantic Kernel, logging, performance, security, SOLID, and code quality. Use when asked for .net/c# or .NET/C# best practices or cleanup.Other plugins' skills for the same job