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 namedMethodName_Scenario_ExpectedBehaviorand 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.Thatwith constraint model (Is.EqualTo,Contains.Item) and specialized assertions likeCollectionAssert,StringAssert, andAssert.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.,
CalculatorTestsforCalculator) - Use .NET SDK test commands:
dotnet testfor running tests