Complete guide for AutoFixture and Bogus integration. Use when you need to combine AutoFixture with Bogus to generate test data that is both anonymous and realistic. Covers SpecimenBuilder integration, hybrid generators, test data factories, and circular reference handling.
Keywords: autofixture bogus integration, autofixture bogus, bogus integration, Faker, EmailSpecimenBuilder, PhoneSpecimenBuilder, NameSpecimenBuilder, realistic test data, semantic data, hybrid generator, HybridTestDataGenerator, OmitOnRecursionBehavior, circular reference
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Complete guide for AutoFixture and Bogus integration. Use when you need to combine AutoFixture with Bogus to generate test data that is both anonymous and realistic. Covers SpecimenBuilder integration, hybrid generators, test data factories, and circular reference handling.
Keywords: autofixture bogus integration, autofixture bogus, bogus integration, Faker, EmailSpecimenBuilder, PhoneSpecimenBuilder, NameSpecimenBuilder, realistic test data, semantic data, hybrid generator, HybridTestDataGenerator, OmitOnRecursionBehavior, circular reference
{"short-description":".NET skill guidance for dotnet-testing-autofixture-bogus-integration"}
copilot
{}
geminicli
{}
antigravity
{}
Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.
AutoFixture and Bogus Integration Application Guide
Applicable Scenarios
Use this skill when asked to perform the following tasks:
Integrate AutoFixture and Bogus tools
Create hybrid test data generators
Design ISpecimenBuilder integrating Bogus data generation
Create custom AutoData attributes using Bogus
Handle circular reference issues
Create unified test data factories
Design test base classes integrating data generation functionality
Core Concepts
Why Integration is Needed?
AutoFixture Advantages:
Quickly generate anonymous test data
Automatically handle complex object structures
Good circular reference handling mechanism
Bogus Advantages:
Generate realistic semantic data
Rich data type support (Email, Phone, Address, etc.)
Data formats friendly to validation
Integrated Effect:
// Problem before integrationvar user = fixture.Create<User>();
// user.Email might be "Email1a2b3c4d", not like a real email// After integrationvar user = integratedFixture.Create<User>();
// user.Email is "john.doe@example.com"// user.FirstName is "John"// Other properties automatically filled by AutoFixture
```text
---
## Package Installation
```xml
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="Bogus" Version="35.6.3" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="AwesomeAssertions" Version="9.1.0" />
```text
---
## Integration Architecture
| Integration Method | Applicable Scenario | Complexity |
| ---------------------------- | ----------------------------- | ---------- |
| Property-level SpecimenBuilder | Specific properties Bogus | Low |
| Type-level SpecimenBuilder | Entire type Bogus | Medium |
|
{
Company? Company { ; ; }
}
{
List<User> Employees { ; ; } = ();
}
```text
**Problem**: User → Company → Employees(User) → Company → ... infinite loop
```csharp
fixture = Fixture();
fixture.Behaviors.OfType<ThrowingRecursionBehavior>()
.ToList()
.ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add( OmitOnRecursionBehavior());
```text
**Effect**:
- ✅ Avoid StackOverflowException
- ✅ Circular reference properties to empty collection
- ⚠️
{
=> Fixture().WithBogus())
{
}
}
```text
```csharp
[]
[]
{
user.Email.Should().Contain();
user.FirstName.Should().NotBeNullOrEmpty();
address.City.Should().NotBeNullOrEmpty();
}
```text
---
```csharp
{
;
;
;
}
```text
```csharp
:
{
IFixture _fixture;
{
_fixture = Fixture()
.WithBogus()
.WithOmitOnRecursion();
(seed.HasValue)
{
Bogus.Randomizer.Seed = Random(seed.Value);
}
}
=> _fixture.Create<T>();
=> Enumerable.Range(, count).Select(_ => Generate<T>());
{
item = Generate<T>();
configure(item);
item;
}
}
```text
---
```csharp
{
IFixture _fixture;
Dictionary<Type, > _cache = ();
{
_fixture = Fixture()
.WithBogus()
.WithOmitOnRecursion()
.WithRepeatCount();
(seed.HasValue)
{
_fixture.WithSeed(seed.Value);
}
}
=> _fixture.Create<T>();
=> _fixture.CreateMany<T>(count).ToList();
{
type = (T);
(_cache.TryGetValue(type, cached))
(T)cached;
instance = CreateFresh<T>();
_cache[type] = instance;
instance;
}
=> _cache.Clear();
{
company = CreateFresh<Company>();
users = CreateMany<User>();
orders = CreateMany<Order>();
( user users)
{
user.Company = company;
}
company.Employees = users;
TestScenario
{
Company = company,
Users = users,
Orders = orders
};
}
}
```text
---
```csharp
{
IFixture Fixture;
HybridTestDataGenerator Generator;
IntegratedTestDataFactory Factory;
{
Fixture = Fixture()
.WithBogus()
.WithOmitOnRecursion()
.WithRepeatCount();
(seed.HasValue)
{
Fixture.WithSeed(seed.Value);
}
Generator = HybridTestDataGenerator(seed);
Factory = IntegratedTestDataFactory(seed);
}
=> Fixture.Create<T>();
=> Fixture.CreateMany<T>(count).ToList();
{
instance = Create<T>();
configure(instance);
instance;
}
}
```text
---
Since AutoFixture Bogus have different random number management mechanisms:
- ✅ Seed ensures test behavior stability
- ✅ Seed ensures data format consistency
- ❌ Cannot guarantee all property values are identical
```csharp
factory = IntegratedTestDataFactory(seed: );
faker = Faker<User>();
faker.UseSeed();
```text
---
```csharp
[]
{
fixture = Fixture().WithBogus();
user = fixture.Create<User>();
user.Email.Should().Contain();
user.FirstName.Should().NotBeNullOrEmpty();
user.Phone.Should().MatchRegex();
}
```text
```csharp
[]
{
factory = IntegratedTestDataFactory(seed: );
scenario = factory.CreateTestScenario();
scenario.Company.Should().NotBeNull();
scenario.Users.Should().HaveCount();
scenario.Orders.Should().HaveCount();
scenario.Users.Should().AllSatisfy(user =>
{
user.Company.Should().Be(scenario.Company);
user.Email.Should().Contain();
});
}
```text
---
**Always handle circular references first**
```csharp
fixture.WithOmitOnRecursion().WithBogus();
```text
**Create dedicated SpecimenBuilders common entities**
**Use Seed to ensure test stability**
**Create test classes to unify data generation logic**
**Use cache appropriately to improve performance**
❌ Over-engineering, keep it simple practical
❌ Expecting integration environment to be fully reproducible
❌ Ignoring circular reference handling
❌ Recreating Fixture every test
---
| Aspect | Pure AutoFixture | Pure Bogus | Integrated Solution |
| ------------------- | ---------------- | -------------- | ------------------- |
| Data Realism | Low | High | High |
| Configuration Complexity | Low | Medium | Medium |
| Object Relationship Handling | Automatic | Manual | Automatic |
| Circular Reference Handling | Built- | None | Integrated |
| Reproducibility | High | High | Medium |
| Applicable Scenarios | Unit tests | Integration tests/Prototypes | Both |
---
This skill content distilled the article series:
- **Day - AutoFixture Bogus Integration: Combining Both Advantages**
- Article: https:
- Sample Code: https:
- [AutoFixture GitHub](https:
- [Bogus GitHub Repository](https:
---
- [autofixture-basics](../autofixture-basics/) - AutoFixture basics
- [autofixture-customization](../autofixture-customization/) - AutoFixture customization strategies
- [autodata-xunit-integration](../autodata-xunit-integration/) - AutoData attribute integration
- [bogus-fake-data](../bogus-fake-data/) - Bogus fake data generator
### Integration Overview
using
using
Hybrid Generator (HybridGenerator) | Unified API integration | Medium |
| Integrated Factory (IntegratedFactory) | Complete test scenario construction | High |
| Custom AutoData Attribute | xUnit integration | Low |
---
## Core Integration Techniques
Implement property-level and type-level integration through the `ISpecimenBuilder` interface, paired with extension methods (`WithBogus()`, `WithOmitOnRecursion()`, `WithSeed()`) to simplify the configuration process. Covers common SpecimenBuilders like Email, Phone, Name, Address, and complete type generator registration patterns.
> For complete content, see [references/core-integration-techniques.md](references/core-integration-techniques.md)
---
## Circular Reference Handling
### Why Circular References are Important?
```csharp
publicclass User
public
get
set
// User references Company
public
class
Company
public
get
set
new
// Company references User
### Solution: OmitOnRecursionBehavior
var
new
new
set
null
or
Some deep properties may be null (thisis expected behavior)
---
## Custom AutoData Attributes
### BogusAutoDataAttribute
```csharp
publicclass BogusAutoDataAttribute : AutoDataAttribute