xunit-skill — Claude Code skill: xUnit.net tests in C#
Gives the coding agent a working pattern for xUnit.net in C#: which attribute to use, how to share fixtures, what to assert. Useful when tests need to match xUnit conventions.
MIT 224 installs ★ 393 updated 2026-10-13
npx skills add LambdaTest/agent-skills --skill xunit-skill -a claude-codeWhat xunit-skill does
The skill hands the agent a reference for xUnit.net work: [Fact] for a single case, [Theory] fed by [InlineData], [MemberData] or [ClassData] for rows of input, and a list of assertion calls running from Assert.Equal to Assert.InRange. Sample code sits alongside, so the agent copies a shape instead of guessing one.
Shared context is wired through IClassFixture<T>. Per-test preparation and teardown go in the constructor and IDisposable. A small anti-pattern table keeps the agent off parameterised [Fact], static state and missing cleanup.
Packages come from dotnet add package xunit xunit.runner.visualstudio Microsoft.NET.Test.Sdk. Leave out Microsoft.NET.Test.Sdk or the runner and dotnet test reports nothing to run. Deeper material lives in reference/playbook.md.
What it helps with
- generate
[Fact]tests for a C# class - split one case into a
[Theory]with[InlineData]rows - share a test database connection through
IClassFixture - close resources in
Disposeafter each test - move static test state into a fixture
Example prompts for the agent
- Write xUnit tests for the
Calculatorclass, including a divide-by-zero case. - Rewrite this test as a
[Theory]with three[InlineData]rows. - Add an
IClassFixturethat opens a test database forUserTests.
How to install xunit-skill
1Skills CLI (Vercel)
npx skills add LambdaTest/agent-skills --skill xunit-skill -a claude-code2Manually: put the files in place
~/.claude/skills/xunit-skill/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/xunit-skill/
1Skills CLI (Vercel)
npx skills add LambdaTest/agent-skills --skill xunit-skill -a codex2Manually: put the files in place
.agents/skills/xunit-skill/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add LambdaTest/agent-skills --skill xunit-skill -a cursor2Manually: put the files in place
.cursor/skills/xunit-skill/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install LambdaTest/agent-skills xunit-skill2Manually: put the files in place
.github/skills/xunit-skill/SKILL.md1Skills CLI (Vercel)
npx skills add LambdaTest/agent-skills --skill xunit-skill -a gemini-cli2Platform CLI
gemini skills install https://github.com/LambdaTest/agent-skills --path xunit-skillManually: put the files in place
.devin/skills/xunit-skill/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add LambdaTest/agent-skills --skill xunit-skill -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about xunit-skill
How to install xunit-skill in Claude Code?
Run npx skills add LambdaTest/agent-skills --skill xunit-skill -a claude-code. The skill lands at ~/.claude/skills/xunit-skill/SKILL.md.
What does xunit-skill do?
It teaches the agent xUnit.net syntax in C#: the [Fact] and [Theory] attributes, data sources, fixtures and the Assert calls.
Which packages does it expect for running tests?
dotnet add package xunit xunit.runner.visualstudio Microsoft.NET.Test.Sdk, then dotnet test, optionally with a filter on the class name.
Source text
SKILL.md · MIT
---
name: xunit-skill
description: >
Generates xUnit.net tests in C#. Covers Fact/Theory, constructor injection,
IClassFixture, and FluentAssertions. Use when user mentions "xUnit",
"[Fact]", "[Theory]", "Assert.Equal", "C# xUnit". Triggers on: "xUnit",
"[Fact]", "[Theory]", "Assert.Equal C#", "xUnit.net".
languages:
- C#
category: unit-testing
license: MIT
metadata:
author: TestMu AI
version: "1.0"
---
# xUnit.net Testing Skill
## Core Patterns
### Basic Test
```csharp
using Xunit;
public class CalculatorTests
{
private readonly Calculator _calc = new();
[Fact]
public void Add_TwoPositiveNumbers_ReturnsSum()
{
Assert.Equal(5, _calc.Add(2, 3));
}
[Fact]
public void Divide_ByZero_ThrowsException()
{
Assert.Throws<DivideByZeroException>(() => _calc.Divide(10, 0));
}
}
```
### Theory (Parameterized)
```csharp
[Theory]
[InlineData(2, 3, 5)]
[InlineData(-1, 1, 0)]
[InlineData(0, 0, 0)]
public void Add_ReturnsCorrectSum(int a, int b, int expected)
{
Assert.Equal(expected, _calc.Add(a, b));
}
[Theory]
[MemberData(nameof(GetTestData))]
public void Add_WithMemberData(int a, int b, int expected)
{
Assert.Equal(expected, _calc.Add(a, b));
}
public static IEnumerable<object[]> GetTestData()
{
yield return new object[] { 1, 2, 3 };
yield return new object[] { -1, -1, -2 };
}
[Theory]
[ClassData(typeof(CalculatorTestData))]
public void Add_WithClassData(int a, int b, int expected)
{
Assert.Equal(expected, _calc.Add(a, b));
}
```
### Assertions
```csharp
Assert.Equal(expected, actual);
Assert.NotEqual(unexpected, actual);
Assert.True(condition);
Assert.False(condition);
Assert.Null(obj);
Assert.NotNull(obj);
Assert.Contains("sub", str);
Assert.DoesNotContain("x", str);
Assert.Empty(collection);
Assert.Single(collection);
Assert.Collection(list,
item => Assert.Equal("first", item),
item => Assert.Equal("second", item));
Assert.IsType<MyClass>(obj);
var ex = Assert.Throws<ArgumentException>(() => Method());
Assert.Equal("message", ex.Message);
Assert.InRange(value, 1, 10);
```
### Shared Context (IClassFixture)
```csharp
public class DatabaseFixture : IDisposable
{
public DbConnection Connection { get; }
public DatabaseFixture() { Connection = new DbConnection("test"); }
public void Dispose() { Connection.Close(); }
}
public class UserTests : IClassFixture<DatabaseFixture>
{
private readonly DatabaseFixture _fixture;
public UserTests(DatabaseFixture fixture) { _fixture = fixture; }
[Fact]
public void GetUser_ReturnsUser()
{
var user = _fixture.Connection.Query<User>("SELECT * FROM Users LIMIT 1");
Assert.NotNull(user);
}
}
```
### Constructor/Dispose (Per-Test Setup)
```csharp
public class MyTests : IDisposable
{
private readonly MyService _service;
public MyTests() { _service = new MyService(); } // SetUp
public void Dispose() { _service.Cleanup(); } // TearDown
[Fact]
public void TestSomething() { Assert.True(_service.IsReady); }
}
```
### Anti-Patterns
| Bad | Good | Why |
|-----|------|-----|
| `[Fact]` with parameters | `[Theory]` + `[InlineData]` | xUnit convention |
| Static state | `IClassFixture` | Test isolation |
| No `IDisposable` | Implement for cleanup | Resource management |
## Setup: `dotnet add package xunit xunit.runner.visualstudio Microsoft.NET.Test.Sdk`
## Run: `dotnet test` or `dotnet test --filter "FullyQualifiedName~Calculator"`
## Deep Patterns
For advanced patterns, debugging guides, CI/CD integration, and best practices,
see `reference/playbook.md`.
© TestMu AI · MIT · LambdaTest/agent-skills