dotnet-testing-autofixture-customization

Customize AutoFixture test data generation with DataAnnotations and ISpecimenBuilder implementations.

1|Updated Mar 1, 2026
One-click install
npx skills add https://github.com/rudironsoni/SharpClaw --skill dotnet-testing-autofixture-customization-rudironsoni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-testing-autofixture-customization
Source: https://github.com/rudironsoni/SharpClaw/tree/main/.github/skills/dotnet-testing-autofixture-customization
Command: npx skills add https://github.com/rudironsoni/SharpClaw --skill dotnet-testing-autofixture-customization-rudironsoni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers overcome limitations in AutoFixture's default test data generation by providing advanced customization techniques for precise control over object creation.

Core Features & Use Cases

  • DataAnnotations Integration: Automatically leverage validation attributes for data generation.
  • Custom Builders: Implement ISpecimenBuilder for fine-grained control over specific properties.
  • Priority Management: Ensure custom builders take precedence using Insert(0).
  • Generic Builders: Create reusable builders for various numeric types with fluent extensions.
  • Use Case: When testing a User model with [Range(18, 65)] for Age, this skill ensures generated User objects always have ages within that range, and can also customize specific DateTime properties like LastLoginDate to fall within a particular year.

Quick Start

Use the dotnet-testing-autofixture-customization skill to generate a Person object with a name of exactly 10 characters and an age between 10 and 80.

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 customize AutoFixture to respect DataAnnotations in .NET?

AutoFixture customization for DataAnnotations integrates validation attributes directly into data generation. This ensures generated objects automatically adhere to constraints like [Range] or string length limits without manual property configuration.

How do I generate test data for specific property ranges using AutoFixture?

To generate specific property ranges in AutoFixture, implement custom ISpecimenBuilder classes. This provides fine-grained control over exact property values, ensuring fields like Age fall within specified numerical bounds.

Why does my custom AutoFixture specimen builder get ignored?

Custom AutoFixture specimen builders are ignored when priority is not set correctly. Ensure your custom builder takes precedence by inserting it at index zero using the Insert(0) method in the customization pipeline.

Can I create generic AutoFixture builders for multiple numeric types in C#?

Yes, you can create generic AutoFixture builders for numeric types in C#. Fluent extensions allow you to build reusable specimen builders that handle various numeric types dynamically for precise test data generation.

How do I generate DateTime properties within a specific year using AutoFixture?

Generating DateTime properties within a specific year using AutoFixture requires a custom ISpecimenBuilder. This intercepts the generation pipeline to constrain date and time values to your defined chronological boundaries.