# Nunit

> NUnit .NET testing framework. Use for .NET testing.

- Skill: `g1joshi/nunit` (Agent Skill)
- Install (CLI): `npx skillmds@latest add g1joshi/nunit`
- Raw SKILL.md: https://api.skillmd.com/api/skills/g1joshi/nunit/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: G1Joshi (https://skillmd.com/u/g1joshi)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/g1joshi/nunit

---


# NUnit

Ported from JUnit, NUnit is one of the oldest and most feature-rich frameworks for .NET. Ideally suited for complex test setups and legacy migrations.

## When to Use

- **Legacy/Enterprise**: Large existing codebases often use NUnit.
- **Complex Lifecycle**: If you really need `[OneTimeSetUp]`, `[SetUp]`, `[TearDown]` hooks which xUnit discourages.
- **Parallelism**: Strong parallel execution support (`[Parallelizable]`).

## Quick Start

```csharp
using NUnit.Framework;

[TestFixture]
public class Tests
{
    [SetUp]
    public void Setup()
    {
    }

    [Test]
    public void Test1()
    {
        Assert.Pass();
    }

    [TestCase(1, 2, 3)]
    [TestCase(2, 2, 4)]
    public void TestAdd(int a, int b, int expected)
    {
       Assert.AreEqual(expected, a + b);
    }
}
```

## Core Concepts

### Constraints Model (Assert.That)

NUnit offers a powerful fluent assertion style.
`Assert.That(result, Is.EqualTo(4));`
`Assert.That(list, Has.Exactly(1).EqualTo("foo"));`

### Attributes

- `[Test]`: Marks a method as a test.
- `[TestCase]`: Parameterized test input.
- `[Category]`: Grouping for filtering (`dotnet test --filter Category=Integration`).

## Best Practices (2025)

**Do**:

- **Use the Constraint Model (`Assert.That`)**: It enables better error messages than `Assert.AreEqual`.
- **Parallel execution**: Enable it in `AssemblyInfo.cs` to speed up lengthy suites. `[assembly: Parallelizable(ParallelScope.Fixtures)]`.

**Don't**:

- **Don't share state in static fields**: NUnit reuses the same test class instance for all tests (unlike xUnit), so dirty static state can leak between tests.

## References

- [NUnit Documentation](https://nunit.org/)

