dotnet-testing-autofixture-customization

Implement custom AutoFixture ISpecimenBuilder and fluent extensions for deterministic test data.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a structured approach to generating realistic and varied test data in .NET unit tests by building custom ISpecimenBuilder implementations and fluent extensions for AutoFixture, enabling deterministic ranges and targeted property control.

Core Features & Use Cases

  • Custom ISpecimenBuilder implementations to precisely control specific property types (for example DateTime ranges and numeric ranges) and extend AutoFixture behavior.
  • Predicate-based targeting and fluent extensions that compose rules for complex models, ensuring consistent data across tests and scenarios.
  • Practical templates and examples demonstrating integration with xUnit and FluentAssertions to validate generated data.

Quick Start

Review the templates under templates/ for representative samples, then adapt them into your test project. Add your own custom builders via fixture.Customizations.Add or the provided AddRandomRange extensions. Run tests to verify generated data respects defined constraints.

Frequently Asked Questions about dotnet-testing-autofixture-customization

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

FAQPage Schema
How do I generate deterministic test data with AutoFixture in .NET?

To generate deterministic test data with AutoFixture, implement custom ISpecimenBuilder implementations to precisely control specific property types like DateTime ranges and numeric fields. This approach ensures consistent test data generation across complex models while avoiding interference from built-in AutoFixture components.

How do I customize AutoFixture to generate DateTime values within a specific range?

You can customize AutoFixture to generate DateTime values within a range by building a custom ISpecimenBuilder and adding it via fixture.Customizations.Add. The provided fluent extensions, such as AddRandomRange, allow you to define predicate-based targeting and compose rules for complex models.

Can I use custom ISpecimenBuilder extensions with xUnit and FluentAssertions?

Yes, custom ISpecimenBuilder extensions integrate with xUnit and FluentAssertions. The provided templates demonstrate how to validate generated data within these testing frameworks, ensuring that your custom test data generation rules work correctly alongside existing unit test setups.

What is the best way to target specific properties in AutoFixture without affecting built-in components?

The best way to target specific properties without affecting built-in components is using predicate-based targeting through custom ISpecimenBuilder implementations. This method applies fine-grained control over complex models and prevents unintended interference from AutoFixture's default generation behavior.

Why does AutoFixture still generate random values outside my defined ranges?

AutoFixture may generate values outside your ranges if built-in components interfere with your rules. Implementing custom ISpecimenBuilder extensions with predicate-based targeting ensures deterministic ranges and targeted property control, overriding default behaviors for specific types like DateTime and numeric fields.