csharp-nunit

Installation
Summary

NUnit best practices for standard and data-driven unit testing in .NET projects.

  • Organize tests with [TestFixture] classes matching production code, using [Test] methods named MethodName_Scenario_ExpectedBehavior and following Arrange-Act-Assert structure
  • Data-driven testing via [TestCase], [TestCaseSource], [Values], [Range], and [Combinatorial] attributes for inline, programmatic, and parameterized test generation
  • Use Assert.That with constraint model (Is.EqualTo, Contains.Item) and specialized assertions like CollectionAssert, StringAssert, and Assert.Throws<T> for exceptions
  • Manage test lifecycle with [SetUp], [TearDown], [OneTimeSetUp], and [OneTimeTearDown] for per-test and per-class initialization
  • Keep tests focused, independent, and idempotent; use [Category], [Order], and [Explicit] for organization and execution control
SKILL.md

NUnit Best Practices

Your goal is to help me write effective unit tests with NUnit, covering both standard and data-driven testing approaches.

Project Setup

  • Use a separate test project with naming convention [ProjectName].Tests
  • Reference Microsoft.NET.Test.Sdk, NUnit, and NUnit3TestAdapter packages
  • Create test classes that match the classes being tested (e.g., CalculatorTests for Calculator)
  • Use .NET SDK test commands: dotnet test for running tests

Test Structure

  • Apply [TestFixture] attribute to test classes
  • Use [Test] attribute for test methods
  • Follow the Arrange-Act-Assert (AAA) pattern
  • Name tests using the pattern MethodName_Scenario_ExpectedBehavior
  • Use [SetUp] and [TearDown] for per-test setup and teardown
  • Use [OneTimeSetUp] and [OneTimeTearDown] for per-class setup and teardown
Related skills

More from github/awesome-copilot

Installs
8.5K
GitHub Stars
32.8K
First Seen
Feb 25, 2026