xunit
Writes unit tests with xUnit framework across 30 test projects. Use when: writing new tests, adding test coverage, creating integration tests, setting up test fixtures, or debugging test failures.
Best use case
xunit is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Writes unit tests with xUnit framework across 30 test projects. Use when: writing new tests, adding test coverage, creating integration tests, setting up test fixtures, or debugging test failures.
Teams using xunit should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/xunit/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How xunit Compares
| Feature / Agent | xunit | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Writes unit tests with xUnit framework across 30 test projects. Use when: writing new tests, adding test coverage, creating integration tests, setting up test fixtures, or debugging test failures.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# xUnit Skill
xUnit is the testing framework to use. Tests use **Shouldly** for readable assertions and **Nsubstitute** for mocking. All tests follow strict `MethodName_Scenario_ExpectedBehavior` naming.
## Quick Start
### Unit Test Structure
```csharp
public class WalletManagerTests
{
private readonly Mock<IRepository<Wallet>> _mockRepository;
private readonly WalletManager _sut;
public WalletManagerTests()
{
_mockRepository = new Mock<IRepository<Wallet>>();
_sut = new WalletManager(_mockRepository.Object);
}
[Fact]
public async Task CreateAsync_ValidWallet_ReturnsSuccess()
{
// Arrange
var wallet = new Wallet { Name = "Test" };
_mockRepository.Setup(r => r.AddAsync(wallet)).ReturnsAsync(wallet);
// Act
var result = await _sut.CreateAsync(wallet);
// Assert
result.IsSuccess.Should().BeTrue();
result.Value.Should().Be(wallet);
}
}
```
### Theory with InlineData
```csharp
[Theory]
[InlineData(12)]
[InlineData(15)]
[InlineData(18)]
[InlineData(21)]
[InlineData(24)]
public void GenerateMnemonic_ValidWordCount_ReturnsCorrectLength(int wordCount)
{
var result = _keyManager.GenerateMnemonic(wordCount);
result.IsSuccess.Should().BeTrue();
result.Value!.Split(' ').Should().HaveCount(wordCount);
}
```
## Key Concepts
| Concept | Usage | Example |
|---------|-------|---------|
| `[Fact]` | Single test case | `[Fact] public void Method_Test() {}` |
| `[Theory]` | Parameterized tests | `[Theory] [InlineData(1)] public void Method(int x) {}` |
| `IClassFixture<T>` | Per-class shared state | `class Tests : IClassFixture<DbFixture>` |
| `ICollectionFixture<T>` | Cross-class shared state | `[Collection("Db")] class Tests` |
| `IAsyncLifetime` | Async setup/teardown | `Task InitializeAsync()`, `Task DisposeAsync()` |
## Common Patterns
### Exception Testing
```csharp
[Fact]
public void Constructor_NullRepository_ThrowsArgumentNullException()
{
var act = () => new WalletManager(null!);
act.Should().Throw<ArgumentNullException>()
.WithParameterName("repository");
}
[Fact]
public async Task ProcessAsync_InvalidData_ThrowsWithMessage()
{
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
() => _processor.ProcessAsync(invalidContext));
exception.Message.Should().Contain("validation failed");
}
```
### Async Test Pattern
```csharp
[Fact]
public async Task ExecuteAsync_ValidBlueprint_CompletesSuccessfully()
{
// Arrange
var blueprint = CreateTestBlueprint();
// Act
var result = await _engine.ExecuteAsync(blueprint);
// Assert
result.Success.Should().BeTrue();
result.ProcessedData.Should().ContainKey("output");
}
```
## See Also
- [patterns](references/patterns.md) - Test patterns and anti-patterns
- [workflows](references/workflows.md) - Test workflows and fixtures
## Related Skills
- See the **dotnet-testing-nsubstitute-mocking** skill for mocking dependencies
- See the **entity-framework** skill for database testing with InMemory provider
## Documentation Resources
> Fetch latest xUnit documentation with Context7.
**How to use Context7:**
1. Use `mcp__context7__resolve-library-id` to search for "xunit"
2. Query with `mcp__context7__query-docs` using the resolved library ID
**Library ID:** `/xunit/xunit.net` _(875 code snippets, High reputation)_
**Recommended Queries:**
- "xUnit Theory InlineData patterns"
- "IClassFixture ICollectionFixture shared context"
- "IAsyncLifetime async setup teardown"
- "xUnit parallel test execution configuration"Related Skills
visual-explainer
Generate beautiful, self-contained HTML pages that visually explain systems, code changes, plans, and data. Use when the user asks for a diagram, architecture overview, diff review, plan review, project recap, comparison table, or any visual explanation of technical concepts. Also use proactively when you are about to render a complex ASCII table (4+ rows or 3+ columns) — present it as a styled HTML page instead.
skill-creator
Guide for creating high-quality Agent Skills following the open standard (agentskills.io). Use this when asked to create or update a skill, write a SKILL.md file, convert custom instructions or chatmodes into portable skills, or design specialized AI agent capabilities.
review-code
Perform comprehensive csharp/dotnet code reviews focusing on clean code, security, testing, performance, and documentation
requirements-engineering
Transform vague feature ideas into lightweight, testable requirements using user stories and short acceptance criteria. Use when clarifying scope, defining expected behavior, capturing edge cases, and producing decision-ready requirements with Definition of Ready checks.
playwright-skill
Complete browser automation with Playwright. Auto-detects dev servers, writes clean test scripts to /.tmp. Test pages, fill forms, take screenshots, check responsive design, validate UX, test login flows, check links, automate any browser task. Use when user wants to test websites, automate browser interactions, validate web functionality, or perform any browser-based testing.
mermaid-diagrams
Comprehensive guide for creating software diagrams using Mermaid syntax. Use when users need to create, visualize, or document software through diagrams including class diagrams (domain modeling, object-oriented design), sequence diagrams (application flows, API interactions, code execution), flowcharts (processes, algorithms, user journeys), entity relationship diagrams (database schemas), C4 architecture diagrams (system context, containers, components), state diagrams, git graphs, pie charts, gantt charts, or any other diagram type. Triggers include requests to "diagram", "visualize", "model", "map out", "show the flow", or when explaining system architecture, database design, code structure, or user/application flows.
grill-me
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
git-commit
Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping
frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.
find-skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entity-framework-core
Entity Framework Core with DbContext, migrations, LINQ queries, relationships, and performance optimization. Covers EF Core 8+ patterns. USE WHEN: user mentions "Entity Framework", "EF Core", "DbContext", "migrations", "LINQ", "EF relationships", "database first", "code first" DO NOT USE FOR: Prisma - use `prisma`, Drizzle - use `drizzle`, Spring Data JPA - use `spring-data-jpa`, Dapper (raw SQL)
dotnet-testing-nsubstitute-mocking
Specialized skill for creating test doubles (Mock, Stub, Spy) using NSubstitute. Use when isolating external dependencies, simulating interface behavior, and verifying method calls. Covers complete guidance on Substitute.For, Returns, Received, Throws, etc.