csharp-nunit

Enforce Arrange-Act-Assert structure and assertion patterns in C# NUnit tests.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-nunit-cloudywing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-nunit
Source: https://github.com/CloudyWing/ai-dotfiles/tree/main/skills/csharp-nunit
Command: npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-nunit-cloudywing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents inconsistent, flaky, or hard-to-read C# unit tests by prescribing a clear structure, naming, and assertion practices so test suites are reliable and maintainable.

Core Features & Use Cases

  • Test Structure & Naming: Requires [Test] attribute for single-case tests, strict Arrange-Act-Assert spacing without inline block comments, and method names in the UnitOfWork_StateUnderTest_ExpectedBehavior format.
  • Data-Driven Tests: Mandates TestCase for inline data, TestCaseSource for complex objects, and Values/Random for combinatorial scenarios to reduce duplication.
  • Assertions & Exceptions: Standardizes Assert.That for equality, Assert.Throws/Assert.ThrowsAsync for exception validation, CollectionAssert/StringAssert for collections and strings, and recommends FluentAssertions if preferred by the project.
  • Isolation & Async: Encourages NSubstitute for mocking, independent idempotent tests that can run in parallel, and async methods to return Task with proper async setup/teardown support.

Quick Start

Create an NUnit test named Calculate_InvalidInput_ThrowsArgumentException that follows Arrange-Act-Assert, uses TestCase for data-driven inputs, mocks dependencies with NSubstitute, and verifies the exception with Assert.Throws.

Frequently Asked Questions about csharp-nunit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure async NUnit tests using the Arrange-Act-Assert pattern in C#?

Structure async NUnit tests by strictly separating Arrange, Act, and Assert sections without inline block comments. Ensure asynchronous tests return a Task type and use Assert.ThrowsAsync for exception validation to maintain reliable execution.

What is the best way to write data-driven NUnit tests for complex objects?

Use TestCaseSource for complex objects and TestCase for inline data in NUnit tests. For combinatorial scenarios, apply Values or Random attributes to reduce duplication while maintaining strict Arrange-Act-Assert spacing.

How does NSubstitute work with NUnit for mocking dependencies in unit tests?

NSubstitute isolates dependencies by mocking interactions within the Arrange section of NUnit tests. This ensures tests remain independent and idempotent, allowing them to run in parallel without flaky behavior.

Can I use FluentAssertions instead of Assert.That in C# NUnit tests?

Yes, FluentAssertions can be used instead of Assert.That if preferred by your project. The standard approach also supports CollectionAssert for collections, StringAssert for strings, and Assert.Throws for exceptions.

Why do my NUnit test names fail naming convention checks?

NUnit test names fail when not matching the UnitOfWork_StateUnderTest_ExpectedBehavior format. Single-case tests must use the [Test] attribute and follow this naming convention to ensure test suites are readable and maintainable.

Does NUnit support parallel execution for idempotent unit tests?

Yes, NUnit supports parallel execution for idempotent unit tests. By encouraging NSubstitute for mocking and ensuring tests are independent, the test suite remains reliable and maintainable when running in parallel.