wshaddix/dotnet-skills/dotnet-xunit
Claude Code and agent skill by wshaddix/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
Writing xUnit tests. v3 Fact/Theory, fixtures, parallelism, IAsyncLifetime, v2 compatibility.
Install
npx vskill@latest install wshaddix/dotnet-skills/dotnet-xunitSKILL.md
dotnet-xunit
xUnit v3 testing framework features for .NET. Covers [Fact] and [Theory] attributes, test fixtures (IClassFixture, ICollectionFixture), parallel execution configuration, IAsyncLifetime for async setup/teardown, custom assertions, and xUnit analyzers. Includes v2 compatibility notes where behavior differs.
Version assumptions: xUnit v3 primary (.NET 8.0+ baseline). Where v3 behavior differs from v2, compatibility notes are provided inline. xUnit v2 remains widely used; many projects will encounter both versions during migration.
Out of scope: Test project scaffolding (creating xUnit projects, package references, Directory.Build.props) is owned by [skill:dotnet-add-testing]. Testing strategy and test type decisions are covered by [skill:dotnet-testing-strategy]. Integration testing patterns (WebApplicationFactory, Testcontainers) are covered by [skill:dotnet-integration-testing].
Prerequisites: Test project already scaffolded via [skill:dotnet-add-testing] with xUnit packages referenced. Run [skill:dotnet-version-detection] to confirm .NET 8.0+ baseline for xUnit v3 support.
Cross-references: [skill:dotnet-testing-strategy] for deciding what to test and how, [skill:dotnet-integration-testing] for combining xUnit with WebApplicationFactory and Testcontainers.
xUnit v3 vs v2: Key Changes
| Feature | xUnit v2 | xUnit v3 | |
|---|---|---|---|
| Package | xunit (2.x) | xunit.v3 | |
| Runner | xunit.runner.visualstudio | xunit.runner.visualstudio (3.x) | |
| Async lifecycle | IAsyncLifetime | IAsyncLifetime (now returns ValueTask) | |
| Assert package | Bundled | Separate xunit.v3.assert (or xunit.v3.assert.source for extensibility) | |
| Parallelism default | Per-collection | Per-collection (same, but configurable per-assembly) | |
| Timeout | Timeout property on [Fact] and [Theory] | Timeout property on [Fact] and [Theory] (unchanged) | |
| Test output | ITestOutputHelper | ITestOutputHelper (unchanged) | |
| `[ClassData]` | Returns IEnumerable<object[]> | Returns IEnumerable<TheoryDataRow<T>> (strongly typed) | |
| `[MemberData]` | Returns IEnumerable<object[]> | Supports TheoryData<T> and TheoryDataRow<T> | |
| Assertion messages | Optional string parameter on Assert methods | Removed in favor of custom assertions (v3.0); use Assert.Fail() for explicit messages |
v2 compatibility note: If migrating from v2, replace xunit package with xunit.v3. Most [Fact] and [Theory] tests work without changes. The primary migration effort is in IAsyncLifetime (return type changes to ValueTask), [ClassData] (strongly typed row format), and removed assertion message parameters.
Facts and Theories
[Fact] -- Single Test Case
Use [Fact] for tests with no parameters:
[Theory] -- Parameterized Tests
Use [Theory] to run the same test logic with different inputs.
[InlineData]
Best for simple value types:
[MemberData] with TheoryData<T>
Best for complex data or shared datasets:
[ClassData]
Best for data shared across multiple test classes:
Fixtures: Shared Setup and Teardown
Fixtures provide shared, expensive resources across tests while maintaining test isolation.
IClassFixture<T> -- Shared Per Test Class
Use when multiple tests in the same class share an expensive resource (database connection, configuration):
v2 compatibility note: In xUnit v2, IAsyncLifetime.InitializeAsync() and DisposeAsync() return Task. In v3, they return ValueTask. When migrating, change the return types accordingly.
ICollectionFixture<T> -- Shared Across Test Classes
Use when multiple test classes need the same expensive resource:
IAsyncLifetime on Test Classes
For per-test async setup/teardown without a shared fixture:
Parallel Execution
Default Behavior
xUnit runs test classes within a collection sequentially but runs different collections in parallel. Each test class without an explicit [Collection] attribute is its own implicit collection, so by default test classes run in parallel.
Controlling Parallelism
Disable Parallelism for Specific Tests
Place tests that share mutable state in the same collection:
Assembly-Level Configuration
Create xunit.runner.json in the test project root:
Ensure it is copied to output:
v2 compatibility note: In v2, configuration was via xunit.runner.json or assembly attributes. v3 retains xunit.runner.json support with the same property names.
Test Output
ITestOutputHelper
Capture diagnostic output that appears in test results:
Integrating with ILogger
Bridge xUnit output to Microsoft.Extensions.Logging for integration tests:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/dotnet-xunit/SKILL.md
Popularity
- Repository stars
- 41
- Repository forks
- 5
- 7-day trend score
- 19
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wshaddix/dotnet-skills/dotnet-xunit)