unit-testing

Generate xUnit unit tests for .NET classes using NSubstitute and FluentAssertions.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill unit-testing-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-testing
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/testing/unit-testing
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill unit-testing-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers produce consistent, maintainable unit tests for .NET projects by applying established xUnit conventions, mocking patterns, and expressive assertions to reduce brittle and hard-to-read tests.

Core Features & Use Cases

  • Consistent Test Style: Enforces Arrange-Act-Assert structure and MethodName_WhenCondition_ShouldExpected naming for clear intent.
  • Mocking Guidance: Recommends NSubstitute (preferred) or Moq for isolating dependencies and shows patterns for verifying behavior.
  • Readable Assertions: Promotes FluentAssertions for expressive checks including collections and async exception assertions.
  • Use Case: Add or refactor unit tests for services, MediatR handlers, validators, and mapping test classes to their corresponding test projects.

Quick Start

Generate xUnit tests using NSubstitute and FluentAssertions for the OrderService class and place them in the corresponding tests project.

Frequently Asked Questions about unit-testing

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

FAQPage Schema
What is the best way to structure .NET unit tests using xUnit?

xUnit unit tests should follow the Arrange-Act-Assert pattern and use the MethodName_WhenCondition_ShouldExpected naming convention to ensure clear intent and maintainable test structures.

How do I generate xUnit tests for MediatR handlers and validators?

You can generate xUnit tests for MediatR handlers and validators by applying established mocking patterns to isolate dependencies and using FluentAssertions for expressive, readable behavioral checks.

Should I use NSubstitute or Moq for mocking dependencies in .NET test projects?

Both NSubstitute and Moq are supported for mocking dependencies in .NET test projects, with NSubstitute being the preferred choice to isolate dependencies and verify behavior patterns.

How do I write expressive assertions for async exceptions in .NET unit tests?

You write expressive assertions for async exceptions and collections in .NET unit tests by using FluentAssertions, which provides readable, fluent syntax for verifying expected outcomes.

How do I ensure consistent naming conventions across service tests in .NET?

You ensure consistent naming conventions across service tests by applying the MethodName_WhenCondition_ShouldExpected pattern, which clearly communicates the tested method, condition, and expected result.