csharp-nunit
github/awesome-copilot
Reference best practices for writing clean, data-driven NUnit tests in C#.
What is csharp-nunit?
This skill provides reference best practices for writing NUnit unit tests in C#, covering project setup, test structure, standard and data-driven testing, assertions, mocking, and test organization. Use it when you want an AI coding agent to generate or review NUnit test code that follows established conventions.
- Defines conventions for structuring NUnit test projects and test classes
- Specifies attribute usage for setup/teardown ([SetUp], [TearDown], [OneTimeSetUp], etc.)
- Guides creation of data-driven tests using NUnit's parameterized test attributes
- Recommends assertion styles including the constraint model (Assert.That) and classic assertions
- Suggests approaches for mocking and test isolation
- Provides conventions for organizing and categorizing tests
How to install csharp-nunit
npx skills add https://github.com/github/awesome-copilot --skill csharp-nunit- A .NET project with a corresponding test project (or willingness to create one)
- NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk NuGet packages
- A coding agent (e.g., GitHub Copilot, Claude Code, Cursor) that can apply this guidance when generating or reviewing code
How to use csharp-nunit
- 1.Ask the agent to scaffold or review a test project following the `[ProjectName].Tests` naming convention with NUnit, NUnit3TestAdapter, and Microsoft.NET.Test.Sdk references
- 2.Request test classes/methods that mirror the code under test, using [TestFixture], [Test], and the MethodName_Scenario_ExpectedBehavior naming pattern
- 3.Ask for standard or data-driven tests using attributes like [TestCase], [TestCaseSource], [Values], or [Range] as appropriate
- 4.Have the agent apply Assert.That with the constraint model (or classic Assert.AreEqual) and appropriate exception/collection/string assertions
- 5.Request mocking setup (e.g., Moq or NSubstitute) to isolate units under test where needed
- 6.Run tests with `dotnet test` and ask the agent to organize tests using [Category], [Order], [Ignore], or [Explicit] as needed
Use cases
- Scaffolding a new NUnit test project with correct package references and naming conventions
- Writing standard unit tests following the Arrange-Act-Assert pattern with clear naming
- Building data-driven tests using TestCase, TestCaseSource, Values, or Range attributes
- Reviewing existing NUnit tests for adherence to assertion and organization best practices
- Setting up mocking with Moq or NSubstitute to isolate units under test
- C# developers writing unit tests with NUnit
- .NET teams standardizing test conventions
- Developers using AI coding agents to generate or review test code
csharp-nunit FAQ
No, it provides best-practice guidance and conventions that the AI agent applies when helping you write or review NUnit tests.
It recommends considering Moq or NSubstitute alongside NUnit for mocking dependencies, but does not set them up for you.
The SKILL.md does not specify a .NET version; it focuses on NUnit attributes, assertion styles, and test organization conventions.
Yes, it covers TestCase, TestCaseSource, Values, ValueSource, Random, Range, Combinatorial, and Pairwise attributes.
Full instructions (SKILL.md)
Source of truth, from github/awesome-copilot.
name: csharp-nunit description: 'Get best practices for NUnit unit testing, including data-driven tests'
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
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 - Use
[SetUpFixture]for assembly-level setup and teardown
Standard Tests
- Keep tests focused on a single behavior
- Avoid testing multiple behaviors in one test method
- Use clear assertions that express intent
- Include only the assertions needed to verify the test case
- Make tests independent and idempotent (can run in any order)
- Avoid test interdependencies
Data-Driven Tests
- Use
[TestCase]for inline test data - Use
[TestCaseSource]for programmatically generated test data - Use
[Values]for simple parameter combinations - Use
[ValueSource]for property or method-based data sources - Use
[Random]for random numeric test values - Use
[Range]for sequential numeric test values - Use
[Combinatorial]or[Pairwise]for combining multiple parameters
Assertions
- Use
Assert.Thatwith constraint model (preferred NUnit style) - Use constraints like
Is.EqualTo,Is.SameAs,Contains.Item - Use
Assert.AreEqualfor simple value equality (classic style) - Use
CollectionAssertfor collection comparisons - Use
StringAssertfor string-specific assertions - Use
Assert.Throws<T>orAssert.ThrowsAsync<T>to test exceptions - Use descriptive messages in assertions for clarity on failure
Mocking and Isolation
- Consider using Moq or NSubstitute alongside NUnit
- Mock dependencies to isolate units under test
- Use interfaces to facilitate mocking
- Consider using a DI container for complex test setups
Test Organization
- Group tests by feature or component
- Use categories with
[Category("CategoryName")] - Use
[Order]to control test execution order when necessary - Use
[Author("DeveloperName")]to indicate ownership - Use
[Description]to provide additional test information - Consider
[Explicit]for tests that shouldn't run automatically - Use
[Ignore("Reason")]to temporarily skip tests
Related skills
More from github/awesome-copilot and the wider catalog.
git-commit
Execute semantic git commits with conventional message analysis and intelligent staging.
excalidraw-diagram-generator
Generate Excalidraw diagrams from natural language descriptions.
documentation-writer
Create structured technical documentation using the Diátaxis framework for tutorials, how-to guides, references, and explanations.
gh-cli
GitHub CLI comprehensive reference for repositories, issues, PRs, Actions, projects, releases, and all GitHub operations from the command line.
prd
Generate comprehensive Product Requirements Documents with executive summaries, user stories, technical specs, and risk analysis.
refactor
Surgical code refactoring to improve maintainability without changing behavior.