Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add LambdaTest/agent-skills --skill xunit-skill -a claude-code
Open on GitHub

What 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 Dispose after each test
  • move static test state into a fixture

Example prompts for the agent

  • Write xUnit tests for the Calculator class, including a divide-by-zero case.
  • Rewrite this test as a [Theory] with three [InlineData] rows.
  • Add an IClassFixture that opens a test database for UserTests.

How to install xunit-skill

1Skills CLI (Vercel)

npx skills add LambdaTest/agent-skills --skill xunit-skill -a claude-code

2Manually: put the files in place

~/.claude/skills/xunit-skill/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/xunit-skill/

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

Similar skills

All skills for Testing and QA →

From the same set47

The whole set →
test-framework-migration-skill test-framework-migration-skill converts E2E test scripts between Selenium, Playwright, Puppeteer, and Cypress. It rewrites selectors, assertions, and lifecycle methods automatically. CX Codex +1 229installs behave-skill Generate Python BDD tests with Gherkin feature files and Behave step implementations. Useful when you need to turn user flows into runnable scenarios. CX Codex +1 227installs karma-skill Builds karma.conf.js for browser-based JavaScript tests on Jasmine, Mocha or QUnit, and shows how to run the suite. CX Codex +1 226installs selenide-skill Generates Java UI tests with Selenide, configuring element selectors, fluent conditions, and automatic waits. CX Codex +1 225installs specflow-skill Drafts SpecFlow BDD suites for C#/.NET: Gherkin feature files plus the step bindings behind them. Useful when a project already runs on NUnit or xUnit. CX Codex +1 223installs serenity-bdd-skill serenity-bdd-skill is a Claude Code skill that creates Java BDD tests with Serenity and the Screenplay pattern. It activates for requests about Serenity, @Steps, or Serenity reports. CX Codex +1 223installs rspec-skill Generates RSpec tests in Ruby with describe/context/it blocks, matchers, let/before hooks, and mocking. Works with Claude Code, Codex, Cursor, GitHub Copilot, and other editors. CX Codex +1 222installs gauge-skill Generates Gauge Markdown test specifications and step implementations in Java, Python, JavaScript, or Ruby. CX Codex +1 218installs

Project sponsors

Companies that keep this analytics open