Creating C# test data without repetition: Test Data Builder, Object Mother, AutoFixture, Bogus

xUnit Testing & CI/CD in .NET November 13, 2026 csharp

Test Data Builder (Q27): valid defaults, and you change only what matters to the test.

csharp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// ======================================================================
// Q: How do you create test data without repetition?
//
// - Test Data Builder (Q27): valid defaults, and you change only what matters to
//   the test. The test shows what counts.
// - Object Mother: ready-made, named objects (TestOrders.PlacedWithTwoLines()).
// - AutoFixture (random values for whatever doesn't matter), Bogus (realistic
//   names and addresses for demo / seed data).
// ======================================================================

var order = new OrderBuilder()
    .ForCustomer(1)
    .WithLine("PIP-100", quantity: 2)
    .Placed()
    .Build();                // everything else: valid defaults