Skip to main content
skill CX Codex

nunit-skill — Claude Code skill: what it does, how to install

Generates C# unit tests for NUnit 3 using the Assert.That constraint model, parameterized inputs, and Moq mocks.

MIT 210 installs ★ 393 updated 2026-10-13

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

What nunit-skill does

This skill guides coding assistants to draft NUnit 3 test suites following current C# patterns. It avoids the legacy Assert.AreEqual syntax, relying instead on constraint assertions like Assert.That(actual, Is.EqualTo(expected)), collection checks, string matchers, and Assert.Throws for exception handling.

Provided templates cover parameterized suites via [TestCase] and [TestCaseSource], test lifecycle hooks ([SetUp], [TearDown], [OneTimeSetUp]), and dependency substitution using Moq. Tests configure mock responses with .Setup() and inspect invocations via .Verify().

Executing the resulting test files requires adding NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk packages to the target test project before running dotnet test.

What it helps with

  • Generate C# unit tests using NUnit 3 constraint syntax
  • Set up parameterized test methods with TestCase and TestCaseSource
  • Mock dependencies and assert call counts using Moq
  • Organize test suites with lifecycle hooks, categories, and timeouts

Example prompts for the agent

  • Generate NUnit 3 tests for the order processing service with Moq mocks
  • Create a parameterized NUnit test for currency parsing with TestCaseSource
  • Write unit tests for the user registration pipeline using Assert.That

How to install nunit-skill

1Skills CLI (Vercel)

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

2Manually: put the files in place

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

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

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about nunit-skill

How to install nunit-skill in Claude Code?

Run npx skills add LambdaTest/agent-skills --skill nunit-skill -a claude-code. The skill file lands in ~/.claude/skills/nunit-skill/SKILL.md.

What does nunit-skill do?

It provides conventions and code structures for generating C# unit tests targeting NUnit 3, including Assert.That constraints, data-driven tests, and Moq mocking.

Which dependencies are required to run the generated code?

Add NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk via dotnet add package, then execute tests with dotnet test.

Source text

SKILL.md · MIT
---
name: nunit-skill
description: >
  Generates NUnit 3 tests in C#. Covers Assert.That constraint model,
  parameterized tests, setup/teardown, and Moq mocking. Use when user mentions
  "NUnit", "[TestFixture]", "[Test]", "Assert.That", "C# unit test". Triggers on:
  "NUnit", "[Test]", "Assert.That", "C# test", "NUnit3".
languages:
  - C#
category: unit-testing
license: MIT
metadata:
  author: TestMu AI
  version: "1.0"
---

# NUnit 3 Testing Skill

## Core Patterns

### Basic Test

```csharp
using NUnit.Framework;

[TestFixture]
public class CalculatorTests
{
    private Calculator _calculator;

    [SetUp]
    public void SetUp() => _calculator = new Calculator();

    [Test]
    public void Add_TwoPositiveNumbers_ReturnsSum()
    {
        Assert.That(_calculator.Add(2, 3), Is.EqualTo(5));
    }

    [Test]
    public void Divide_ByZero_ThrowsException()
    {
        Assert.Throws<DivideByZeroException>(() => _calculator.Divide(10, 0));
    }

    [TearDown]
    public void TearDown() { /* cleanup */ }
}
```

### Constraint Model (Assert.That)

```csharp
Assert.That(actual, Is.EqualTo(expected));
Assert.That(actual, Is.Not.EqualTo(unexpected));
Assert.That(value, Is.GreaterThan(5));
Assert.That(value, Is.InRange(1, 10));
Assert.That(str, Does.Contain("hello"));
Assert.That(str, Does.StartWith("He").IgnoreCase);
Assert.That(collection, Has.Count.EqualTo(3));
Assert.That(collection, Has.Member("item"));
Assert.That(collection, Is.All.GreaterThan(0));
Assert.That(obj, Is.Null);
Assert.That(obj, Is.Not.Null);
Assert.That(obj, Is.InstanceOf<MyClass>());
Assert.That(actual, Is.EqualTo(3.14).Within(0.01));
Assert.That(() => Method(), Throws.TypeOf<ArgumentException>()
    .With.Message.Contains("invalid"));
```

### Parameterized Tests

```csharp
[TestCase(2, 3, 5)]
[TestCase(-1, 1, 0)]
[TestCase(0, 0, 0)]
public void Add_ReturnsCorrectSum(int a, int b, int expected)
{
    Assert.That(_calculator.Add(a, b), Is.EqualTo(expected));
}

[TestCaseSource(nameof(DivisionCases))]
public void Divide_ReturnsCorrectQuotient(int a, int b, double expected)
{
    Assert.That(_calculator.Divide(a, b), Is.EqualTo(expected).Within(0.01));
}

private static IEnumerable<TestCaseData> DivisionCases()
{
    yield return new TestCaseData(10, 2, 5.0).SetName("10/2=5");
    yield return new TestCaseData(7, 3, 2.33).SetName("7/3=2.33");
}
```

### Mocking with Moq

```csharp
using Moq;

[TestFixture]
public class UserServiceTests
{
    private Mock<IUserRepository> _mockRepo;
    private Mock<IEmailService> _mockEmail;
    private UserService _service;

    [SetUp]
    public void SetUp()
    {
        _mockRepo = new Mock<IUserRepository>();
        _mockEmail = new Mock<IEmailService>();
        _service = new UserService(_mockRepo.Object, _mockEmail.Object);
    }

    [Test]
    public void CreateUser_SavesAndSendsEmail()
    {
        _mockRepo.Setup(r => r.Save(It.IsAny<User>())).Returns(new User { Id = 1 });

        var result = _service.CreateUser("[email protected]", "Alice");

        Assert.That(result.Id, Is.EqualTo(1));
        _mockRepo.Verify(r => r.Save(It.IsAny<User>()), Times.Once);
        _mockEmail.Verify(e => e.SendWelcome("[email protected]"), Times.Once);
    }
}
```

### Lifecycle

```
[OneTimeSetUp]    → Before all tests in fixture
[SetUp]           → Before each test
[Test]            → Test method
[TearDown]        → After each test
[OneTimeTearDown] → After all tests in fixture
```

### Categories and Attributes

```csharp
[Test, Category("Smoke")]
public void QuickTest() { }

[Test, Ignore("Bug #123")]
public void SkippedTest() { }

[Test, Timeout(5000)]
public void TimeLimitedTest() { }

[Test, Retry(3)]
public void FlakyTest() { }
```

### Anti-Patterns

| Bad | Good | Why |
|-----|------|-----|
| `Assert.AreEqual(a, b)` (classic) | `Assert.That(a, Is.EqualTo(b))` | Constraint model is richer |
| No `[SetUp]` | Proper lifecycle | Resource management |
| Testing private methods | Test public API | Encapsulation |
| No categories | `[Category("Smoke")]` | Run subsets |

## Setup: `dotnet add package NUnit NUnit3TestAdapter Microsoft.NET.Test.Sdk`
## Run: `dotnet test` or `dotnet test --filter TestCategory=Smoke`

## 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 →
testunit-skill testunit-skill generates Test::Unit tests for Ruby projects: xUnit-style classes, assert methods and fixtures. Fits codebases already running on test-unit rather than RSpec. CX Codex +1 213installs testcafe-skill Generate TestCafe end-to-end tests in JavaScript or TypeScript, from login flows to selector checks. The skill covers local runs and TestMu AI Cloud. CX Codex +1 212installs geb-skill This skill generates browser automation tests in Groovy using Geb and Spock. It provides page object patterns and jQuery-like selectors for e2e testing. CX Codex +1 211installs capybara-skill Generates acceptance tests for web apps using Capybara and RSpec. Use it to automate clicks, form fills, and page assertions in Ruby-based E2E suites. CX Codex +1 210installs mstest-skill This skill generates MSTest unit tests in C# for .NET. Use it when a task calls for [TestMethod], assertion checks, or data-driven cases. CX Codex +1 209installs nemojs-skill The nemojs-skill skill generates JavaScript automation tests for Nemo.js and Selenium. Use it for browser flows such as login checks, element waits, and assertions. CX Codex +1 209installs lettuce-skill Generates Python BDD tests using the legacy Lettuce framework. Builds Gherkin feature files, step definitions, and terrain hooks for existing test suites. CX Codex +1 208installs nightwatchjs-skill Writes NightwatchJS E2E tests in JavaScript or TypeScript, with page objects and built-in assertions. Fits repos that already run Nightwatch. CX Codex +1 208installs

Project sponsors

Companies that keep this analytics open