From qa-unit-tests-net
Configures and runs NUnit - JVM-style attribute-driven .NET test framework with `[Test]` / `[TestCase]` / `[TestCaseSource]` / `[Values]` / `[Random]` parametrize attributes; `[SetUp]` / `[TearDown]` / `[OneTimeSetUp]` / `[OneTimeTearDown]` lifecycle; categories for selective runs; constraint-model assertion API (`Assert.That(actual, Is.EqualTo(expected))`); parameterized fixtures via `[TestFixture]` typed args. Use when working with .NET on a NUnit codebase or preferring constraint-model assertions over xUnit's classic style.
How this skill is triggered — by the user, by Claude, or both
Slash command
/qa-unit-tests-net:nunit-testsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Per [docs.nunit.org][nu-docs]:
Per docs.nunit.org:
NUnit (port of JUnit to .NET, originally) was the dominant .NET test framework before xUnit gained traction. Still actively maintained; widely used in legacy + new projects with team preference.
Distinguishing properties vs xUnit:
Assert.That(value, Is.EqualTo(expected)))[TestCase], [Values],
[Random], [Range])Assert.Equal().[Random]/[Range] (light
property-based without ScalaCheck-equivalent).For new code, xunit-tests is more
mainstream in 2026.
dotnet new nunit -n MyTests
# Or:
dotnet add package NUnit
dotnet add package NUnit3TestAdapter
dotnet add package Microsoft.NET.Test.Sdk
using NUnit.Framework;
[TestFixture]
public class CalculatorTests
{
[Test]
public void Adds_TwoNumbers()
{
Assert.That(Calculator.Add(1, 2), Is.EqualTo(3));
}
}
The [TestFixture] annotation is optional in NUnit 3+; classes
with [Test] methods are auto-discovered. Convention varies - some
teams require [TestFixture] for explicitness.
Run: dotnet test.
Per nu-docs:
[Test]
[TestCase(1, 2, 3)]
[TestCase(0, 0, 0)]
[TestCase(-1, 1, 0)]
public void Adds_VariousInputs(int a, int b, int expected)
{
Assert.That(Calculator.Add(a, b), Is.EqualTo(expected));
}
[Test]
public void Adds_FromValues(
[Values(1, 2, 3)] int a,
[Values(0, 1)] int b)
{
// Combinatorial: 3 × 2 = 6 test runs
Assert.That(Calculator.Add(a, b), Is.EqualTo(a + b));
}
[Test]
public void Adds_Random(
[Random(0, 100, 5)] int a,
[Random(0, 100, 5)] int b)
{
// 5 random values × 5 = 25 runs with random ints in [0, 100)
Assert.That(Calculator.Add(a, b), Is.EqualTo(a + b));
}
[Test]
public void Adds_Range([Range(0, 10, 2)] int n)
{
// n = 0, 2, 4, 6, 8, 10
Assert.That(Calculator.Add(n, n), Is.EqualTo(n * 2));
}
// Method-source
[Test]
[TestCaseSource(nameof(AddCases))]
public void Adds_FromSource(int a, int b, int expected) { ... }
public static IEnumerable<TestCaseData> AddCases()
{
yield return new TestCaseData(1, 2, 3);
yield return new TestCaseData(0, 0, 0);
}
Per nu-docs:
Assert.That(value, Is.EqualTo(expected));
Assert.That(value, Is.Not.EqualTo(expected));
Assert.That(value, Is.GreaterThan(0));
Assert.That(string, Does.Contain("substring"));
Assert.That(string, Does.Match("regex"));
Assert.That(list, Has.Count.EqualTo(3));
Assert.That(list, Has.Member("alice"));
Assert.That(list, Is.Ordered);
Assert.That(list, Has.All.GreaterThan(0));
Assert.That(opt, Is.Null);
Assert.That(opt, Is.Not.Null);
Assert.That(value, Is.InstanceOf<MyClass>());
Assert.That(value, Is.TypeOf<MyClass>()); // strict type
Assert.That(action, Throws.TypeOf<ArgumentException>());
Assert.That(actual, Is.EqualTo(0.0).Within(0.001)); // float tolerance
The constraint model composes (Is.Not.Null.And.Not.Empty) and
produces detailed failure messages.
Classic-model assertions (Assert.AreEqual, Assert.IsTrue) still
work but are discouraged in NUnit 3+.
[TestFixture]
public class TestsWithLifecycle
{
[OneTimeSetUp]
public void OneTimeSetUp() { /* once before all tests in fixture */ }
[OneTimeTearDown]
public void OneTimeTearDown() { /* once after */ }
[SetUp]
public void SetUp() { /* before each test */ }
[TearDown]
public void TearDown() { /* after each test */ }
[Test]
public void Test1() { ... }
}
[Test]
[Category("Slow")]
public void SlowTest() { }
[Test]
[Category("Integration")]
public void IntegrationTest() { }
// Filter at runtime:
// dotnet test --filter Category=Integration
[TestFixture("postgres")]
[TestFixture("mysql")]
public class DatabaseTests
{
private string _engine;
public DatabaseTests(string engine) { _engine = engine; }
[Test]
public void Connect()
{
// runs against postgres AND mysql
}
}
Same pattern as xUnit:
- run: dotnet test --logger "trx;LogFileName=test-results.trx" \
--collect:"XPlat Code Coverage"
| Anti-pattern | Why it fails | Fix |
|---|---|---|
Use classic Assert.AreEqual style | Discouraged in NUnit 3+ | Use constraint model Assert.That(...) (Step 4) |
[Test] without [TestFixture] in mixed-style codebase | Discovery inconsistencies | Pick a convention; document |
Heavy use of [Random] | Non-deterministic test runs | Set seed via [Random(seed: 42, ...)] for reproducibility |
| Mix NUnit + xUnit | Two runners | Pick one |
Assert.Equal() simplicity.[Random] tests need seed pinning for CI reproducibility.xunit-tests,
mstest-tests,
fluentassertions - sister toolstest-code-conventionsnpx claudepluginhub testland/qa --plugin qa-unit-tests-netProvides CDSS development patterns for drug interaction checking, dose validation, clinical scoring (NEWS2, qSOFA), and alert classification integrated into EMR workflows.