kevintsengtw/dotnet-testing-agent-skills
Overview
This skill is a practical guide to advanced AutoFixture customization for .NET tests. It explains how to integrate DataAnnotations, implement ISpecimenBuilder for precise control, and manage builder priority so generated test data matches business constraints. The content includes reusable generic numeric builders, DateTime range generators, and fluent extension methods for easy fixture composition.
How this skill works
The skill inspects property requests made to AutoFixture and provides custom values when a request matches configured predicates (property name, declaring type, or attribute). Custom ISpecimenBuilder implementations return a concrete value for matching requests or NoSpecimen to defer to the next builder. Insert(0) is used to ensure custom builders run before built-in relays that might intercept numeric or ranged values.
When to use it
- When model validation attributes (StringLength, Range, etc.) must be honored in generated test data.
- When specific properties need values constrained to a DateTime or numeric range.
- When built-in AutoFixture generators produce undesired values for certain properties.
- When creating reusable, type-safe range generators across multiple value types.
- When you need deterministic but varied test datasets for integration or property tests.
Best practices
- Leverage DataAnnotations on models and let AutoFixture respect them where possible.
- Use Random.Shared for thread-safe, non-repeating random value generation.
- Register numeric or property-specific builders with fixture.Customizations.Insert(0) to guarantee priority.
- Keep specimen builders single-responsibility and return NoSpecimen for non-target requests.
- Provide fluent extension methods to compose multiple range rules clearly in tests.
Example use cases
- Create Persons where Name length and Age match StringLength and Range attributes automatically.
- Control UpdateTime only, generating dates between two boundaries while leaving other DateTime fields untouched.
- Enforce Price, Quantity, Rating, Discount ranges on Product objects using a generic NumericRangeBuilder<T>.
- Replace built-in numeric generators for a domain property (e.g., Age) to avoid interception by RangeAttributeRelay.
- Add chained AddRandomRange<T, TValue> calls to a Fixture to express complex test data constraints concisely.
FAQ
Built-in AutoFixture relays like RangeAttributeRelay or NumericSequenceGenerator can intercept numeric requests. Insert(0) puts your builder at highest priority so your rule executes first.
When should a builder return NoSpecimen?
Return NoSpecimen for any request your builder does not target (wrong type, property name, or attribute). This delegates creation to the next builder in the chain and avoids side effects.
16 skills
This skill guides advanced AutoFixture customization for .NET tests, enabling precise data generation with ISpecimenBuilder, DataAnnotations, and fluent
This skill streamlines .NET testing by auto-mocking interface dependencies with AutoFixture AutoNSubstitute, reducing boilerplate and improving test resilience.
This skill helps you quickly match advanced .NET testing needs to the right sub-skills, enabling guided integration, container, and framework migration testing.
This skill helps you build advanced WebApi integration tests using WebApplicationFactory, ProblemDetails validation, and multi-container test environments.
This skill helps you test time dependent logic in .NET by using TimeProvider, enabling controllable clocks, time freezing, and expiry scenarios.
This skill helps you implement end-to-end integration tests for .NET Aspire distributed apps using AppHost, container lifecycles, and real services.
This skill helps you write fluent, readable tests with AwesomeAssertions for objects, collections, and exceptions, boosting clarity and diagnostics.
This skill guides upgrading xUnit 2.x projects to 3.x, enabling migration best practices, async lifecycle updates, and new features for robust tests.
This skill helps you write clear, maintainable test data using the Test Data Builder pattern in .NET, improving test readability and reuse.
This skill guides advanced Testcontainers NoSQL integration testing for MongoDB and Redis, enabling efficient containerized tests with collection fixtures and
This skill helps you implement .NET unit testing fundamentals with FIRST principles, AAA pattern, and xUnit guidance to improve test quality.
This skill guides implementing structured test output and logging in xUnit with ITestOutputHelper, AbstractLogger, and diagnostic tools for .NET tests.
This skill enables realistic database testing with Testcontainers in .NET, orchestrating containerized SQL Server and PostgreSQL for EF Core and Dapper tests.
This skill helps you name tests and test classes using three-part naming, improving readability and consistency across .NET test suites.
This skill enables advanced TUnit testing with data-driven, dependency injection, and integration testing techniques to boost reliability and coverage.
This skill guides you through setting up, running, and interpreting code coverage for .NET tests, improving coverage reports and CI/CD integration.