dotnet-testing-autofixture-nsubstitute-integration

Automate mock creation for .NET unit tests using AutoFixture.AutoNSubstitute with xUnit.

28|4|Updated Jan 20, 2026
One-click install
npx skills add https://github.com/kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-autofixture-nsubstitute-integration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-testing-autofixture-nsubstitute-integration
Source: https://github.com/kevintsengtw/dotnet-testing-agent-skills/tree/main/skills/dotnet-testing-autofixture-nsubstitute-integration
Command: npx skills add https://github.com/kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-autofixture-nsubstitute-integration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When writing unit tests in .NET, developers often hand-roll mocks for multiple dependencies, which creates boilerplate and brittle tests. This Skill automates substitution using AutoFixture.AutoNSubstitute, enabling automatic mock creation for interfaces and abstract types so tests remain focused on behavior.

Core Features & Use Cases

  • Auto-mocking of interfaces and abstract classes via AutoFixture.AutoNSubstitute.
  • Simplified test setup for services with multiple dependencies using [Frozen], [AutoData], and custom AutoData attributes.
  • Seamless integration with xUnit and NuGet-based setup for rapid test scaffolding.

Quick Start

Install required NuGet packages:

  • AutoFixture.AutoNSubstitute
  • AutoFixture
  • AutoFixture.Xunit2 Then write tests using [Theory] and [AutoDataWithCustomization] or [AutoNSubstituteData], and freeze dependencies to share instances across the system under test.

Frequently Asked Questions about dotnet-testing-autofixture-nsubstitute-integration

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

FAQPage Schema
How do I reduce manual mocking boilerplate in .NET unit tests?

Auto-mocking in .NET unit tests eliminates manual mocking boilerplate by using AutoFixture.AutoNSubstitute to automatically wire substitutes for interface and abstract type dependencies. This keeps tests focused on behavior rather than setup code.

How do I set up AutoFixture with NSubstitute and xUnit for auto-mocking?

To set up auto-mocking, install the AutoFixture.AutoNSubstitute and AutoFixture.Xunit2 NuGet packages. Then apply custom AutoData attributes like [AutoNSubstituteData] to xUnit [Theory] tests to enable automatic mock creation.

Can I share a mocked dependency instance across the system under test in xUnit?

Yes, you can share a mocked dependency instance across the system under test by applying the [Frozen] attribute alongside your AutoData attributes in xUnit. This ensures the exact same substitute is injected throughout the test.

Does AutoFixture auto-mocking work with services that have multiple constructor dependencies?

Yes, AutoFixture.AutoNSubstitute handles services with multiple dependencies by automatically injecting substitutes for all interfaces and abstract types via constructor injection, simplifying complex test scenarios.

Why use AutoFixture.AutoNSubstitute instead of hand-rolling mocks in C#?

Using AutoFixture.AutoNSubstitute instead of hand-rolling mocks prevents brittle tests caused by manual boilerplate. It automates substitution for abstract types and interfaces, keeping your C# unit tests focused on actual behavior.