Skill

Create Comprehensive NUnit Test Suites

An NUnit test-writing skill covering the AAA pattern, constraint-based assertions, parameterized and async tests, and Moq mocking.

Works with nunit

Maintainer of this project? Claim this page to edit the listing.


88
Spark score
out of 100
Updated 7 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Automate the creation of robust and maintainable NUnit test suites for .NET applications. Ensure code quality and reliability by generating tests that follow industry best practices and advanced assertion patterns.

Outcomes

What it gets done

01

Generate unit tests following AAA pattern

02

Implement parameterized tests using TestCase and TestCaseSource

03

Create tests for async methods and exception handling

04

Incorporate mocking with Moq for dependency injection

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-nunit-test-creator | bash

Overview

NUnit Test Creator

An NUnit test-writing skill covering the AAA pattern, NUnit attributes, constraint-based assertions, parameterized and async testing, and Moq-based mocking for .NET code. Use it when writing or reviewing NUnit test suites for .NET, especially when parameterizing tests, testing async code, or mocking dependencies.

What it does

This skill creates comprehensive NUnit test suites for .NET applications following the Arrange-Act-Assert pattern, descriptive scenario-and-outcome test names, and proper test isolation. It covers the essential NUnit attributes - [Test], [TestFixture], [SetUp], [TearDown], [OneTimeSetUp], [OneTimeTearDown], [TestCase], and [TestCaseSource] - and demonstrates a full test class structure with fixture-level and per-test setup and teardown.

It covers advanced constraint-based assertions (string, collection, and object assertions using Is, Does, Has, and Contains constraints), exception testing with Assert.Throws and property-level checks on the thrown exception, parameterized tests using both inline [TestCase] data and external [TestCaseSource] data providers, async testing with async Task test methods and timeout-based exception assertions, and test categorization and filtering with the [Category] attribute for separating integration from fast unit tests.

Best-practice guidance covers test naming conventions (MethodName_StateUnderTest_ExpectedBehavior, avoiding abbreviations and jargon), reusable test data builders - a static factory class with methods like CreateValidPerson() and CreateProductList() that return ready-to-use objects instead of duplicating construction logic in every test - and mocking dependencies with Moq (setting up return values with Setup, and verifying call counts with Verify and Times.Once). Test organization tips include keeping tests small and focused on a single behavior, using meaningful setup/teardown, maintaining test independence so no test depends on another, grouping related tests in nested classes when appropriate, and covering both positive and negative cases plus boundary conditions.

[Test]
public void Divide_WhenDivideByZero_ThrowsArgumentException()
{
    // Arrange
    var calculator = new Calculator();

    // Act & Assert
    var ex = Assert.Throws<ArgumentException>(() => calculator.Divide(10, 0));
    Assert.That(ex.Message, Does.Contain("Cannot divide by zero"));
}

When to use - and when NOT to

Use this skill when writing or reviewing NUnit test suites for .NET code - structuring test fixtures, choosing between constraint-based assertions, parameterizing tests with TestCase or TestCaseSource, testing async methods and expected exceptions, or mocking dependencies with Moq.

It is not a fit for other .NET test frameworks (xUnit, MSTest) - the attributes, constraint syntax, and categorization approach here are NUnit-specific - or for integration/end-to-end test infrastructure beyond the [Category("Integration")] tagging convention it shows.

Inputs and outputs

Inputs are the class or method under test and the scenarios you need covered (happy path, edge cases, exceptions, async behavior). Outputs are complete NUnit test classes with AAA-structured test methods, constraint-based assertions, parameterized TestCase/TestCaseSource variants where applicable, and Moq-based mocks for external dependencies.

Integrations

Built on the NUnit test framework and its constraint model (Assert.That, Is/Does/Has/Contains), with Moq for mocking dependencies in isolation.

Who it's for

.NET developers writing or maintaining NUnit test suites who want consistent structure, correct use of NUnit's parameterization and async testing features, and Moq-based mocking, rather than assembling test patterns from the NUnit documentation piecemeal.

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.