Guides

Customizing

How customizers and defaults work together and why their order matters.

The one rule

A factory gives tests a valid district to start from. A test can customize that district when its behavior depends on a different value.

Changing when a teacher was invited should also change when the invitation expires by default. If the test supplies the expiry itself, that value should survive. Biome runs derived defaults after customizers to support both choices.

Customizers choose the values; derived and global defaults fill what is still unset. More specific defaults run before global ones.

For every entity in an Add step, Biome runs the same pipeline, in this order:

  1. Factory creates the entity. IDs are set here with ctx.NewId.
  2. Traits (.With) run, in declaration order.
  3. Call-site customizers run.
  4. Derives run, fill-only and in declaration order. Sequences first reserve every explicit value in the step, then fill the rest.
  5. Global defaults (options.Default) run, fill-only.
  6. The entity is recorded, with its parent link and step.

There is no OnCreated hook that can overwrite a value. Steps 4 and 5 only fill properties that are still unset.

An input blueprint runs steps 2 to 4 on its input object (traits and customizers for every input in the step first, then each input's Derives followed by the factory), and then applies global defaults to the built entity (step 5).

Set only the property under test

A district report excludes archived districts. The setup creates one ordinary district and one archived district, so the reader can see which property drives the filter.

await TestBiome
    .Start(_db, out _)
    .AddDistrict(out var active)
    // The report uses this flag to exclude the district.
    .AddDistrict(out var archived, d => d.IsArchived = true)
    .BuildAsync();
A repeated default looks just as deliberate as a value chosen for the assertion. Set only the properties the test depends on, so the reader can see why this scenario exists.

Traits: comma makes a new entity, plus stacks

If several tests make the same choice, give it a handle to make it reusable. A trait is an Action<T> value that you can pass anywhere a customizer goes.

The Quick start defines separate district traits for archiving and choosing a time zone.

Districts.cs
public static class Districts
{
    // Name common states so tests can reuse and combine them.
    public static readonly Action<District> Archived = d => d.IsArchived = true;
    public static readonly Action<District> Pacific = d => d.TimeZoneId = "America/Los_Angeles";
}
Traits in a chain
await TestBiome
    .Start(out _)
    .Add(
        Blueprints.District,
        out var districts,
        // Both districts are archived. Only the second uses Pacific time.
        Districts.Archived,
        Districts.Archived + Districts.Pacific
    )
    .BuildAsync();
Choose + when one entity needs both traits, and a comma when the test needs separate entities.

Bake a trait into a variant with .With. Each blueprint keeps its own traits.

Blueprints.cs
// Make archiving the default for callers that choose this variant.
public static readonly Blueprint<SchoolSeed, District> ArchivedDistrict = District.With(
    Districts.Archived
);

Context-aware customizers

Use two parameters when a customizer needs context. This test uses the shared clock to backdate a student’s enrollment.

Relative time
await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClass(out _)
    .AddOne(
        Blueprints.Student,
        out var returningStudent,
        // Backdate enrollment relative to the clock shared by this scenario.
        (student, ctx) => student.EnrolledAtUtc = ctx.Ago(TimeSpan.FromDays(30))
    )
    .BuildAsync();
When a customizer needs context, write all the lambdas in that Add call in the two-parameter form. Generated grafts accept Action<T> (or Action<TInput> for an input blueprint) unless the app has added a context overload for that type; otherwise a context-aware customizer goes through the core Add / AddOne.

Derived defaults are fill-only

Some defaults depend on the entity's final values. A staff invitation expires seven days after it was created, so the expiry needs the creation time that remains after traits and customizers run. .Derive fills the expiry if it still has its default value.

Blueprints.cs
public static readonly ChildBlueprint<SchoolSeed, School, StaffInvitation> StaffInvitation =
    Blueprint
        .ChildOf<SchoolSeed, School, StaffInvitation>(
            (school, ctx) =>
                new()
                {
                    Id = ctx.NewId("invite"),
                    DistrictId = school.DistrictId,
                    SchoolId = school.Id,
                    Email = "teacher@example.test",
                    CreatedAtUtc = ctx.Now,
                }
        )
        // Calculate expiry after the caller has had a chance to change the creation time.
        .Derive(i => i.ExpiresAtUtc, (i, _) => i.CreatedAtUtc.AddDays(7));
StaffInvitationTests.cs
var created = new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .Add(
        Blueprints.StaffInvitation,
        out var invitations,
        // The new creation time puts the default expiry on January 8. An explicit expiry wins.
        i => i.CreatedAtUtc = created,
        i =>
        {
            i.CreatedAtUtc = created;
            i.ExpiresAtUtc = created.AddDays(1);
        }
    )
    .BuildAsync();

What counts as "unset"

TypeUnset means
reference types, T?null
numbers, bool0, false
DateTimeOffsetdefault(DateTimeOffset)
stringnull only. "" counts as set.
Biome uses the type's default value to recognize an unset property. For a string that means null, so "" is kept as an explicit value. Leave derived strings null in the factory. If a test needs to retain null, use a base blueprint without that Derive.

For nullable value types the distinction holds too: int? null fills, but 0 survives.

Derives run in order

The student blueprint uses the seat number in its default name. Derives run in declaration order, so assign the seat before reading it for the name.

Blueprints.cs
    // Assign the seat first so the name can use its number.
    .Derive(s => s.Seat, Seats)
    .Derive(s => s.FullName, (s, _) => $"Student {s.Seat}")

Properties must be settable

A customizer cannot assign an init property (CS8852), so a property that a test varies on the entity itself needs a set. If the model must stay init or required, keep production code as it is and customize an input instead: see Input blueprints. A blueprint factory method with optional named parameters also works, but it creates a new blueprint on every call.

The property you select in Derive or options.Default must be a directly writable instance property, like e => e.Name. Anything else throws ArgumentException at declaration time. init properties are accepted here, because Derive and Default assign through a compiled setter.