Use the open-source free `coverlet` toolchain for .NET code coverage.
NUnit Testing
Write, run, or repair .NET tests that use NUnit. Use when a repo uses `NUnit`, `[Test]`, `[TestCase]`, `[TestFixture]`, or NUnit3TestAdapter for VSTest or Microsoft.Testing.Platform execution. USE FOR: writing or reviewing NUnit tests; using [Test], [TestCase], [TestFixture], [SetUp], [TearDown] attributes; configuring NUnit3TestAdapter or NUnit.Analyzers. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.
Trigger On
- writing or reviewing NUnit tests
- using
[Test],[TestCase],[TestFixture],[SetUp],[TearDown]attributes - configuring NUnit3TestAdapter or NUnit.Analyzers
- migrating between NUnit versions
- integrating NUnit with CI pipelines
Workflow
- Detect whether the project uses NUnit 3.x or 4.x and which runner path is active: VSTest, Microsoft.Testing.Platform, IDE runner, or CI wrapper.
- Keep test fixtures small, prefer focused assertions with
Assert.That, and useTestCaseorTestCaseSourceonly when parameterization improves signal. - Add
NUnit3TestAdapter,Microsoft.NET.Test.Sdk, andNUnit.Analyzerswhen CLI discovery or analyzer coverage is missing. - Validate with the repo's real test command before changing assertion style or lifecycle hooks.
References
- patterns.md — Test patterns, assertions, parameterized tests, lifecycle
- anti-patterns.md — Common NUnit mistakes and fixes
Deliver
- NUnit tests following the Arrange-Act-Assert pattern
- Parameterized tests with
[TestCase]and[TestCaseSource] - Constraint-based assertions with
Assert.That - Proper test lifecycle management
Validate
- Tests are independent and isolated
- No hardcoded test data where parameterization is appropriate
- Async tests use
async Tasknotasync void - Resources are properly disposed in
[TearDown]or[OneTimeTearDown] - NUnit.Analyzers enabled to catch common issues
Related skills
coverlet.collectorcoverlet.msbuild
Write, run, or repair .NET tests that use MSTest.
MSTestMSTest.TestFrameworkMSTest.TestAdapter
Analyzes the variety and depth of assertions across test suites in any language.