Seed data is a carefully chosen starting dataset loaded into a database before scenarios run. It can save scenarios from repeatedly creating common data, but scenarios that need custom data must replace or bypass the seeded records. section 18.4
Before sharing data across scenarios:
- Check how often scenarios need it, and provide a way for scenarios with different data requirements to avoid conflicts. section 18.4
- If custom-data scenarios use a common setup step, have that step replace the seeded data. If undoing the seed adds significant runtime, consider excluding it with a tag. section 18.4
A shared restaurant menu
A database reset seeds Margherita, Pepperoni, and Capricciosa. A promotion scenario that specifies its own menu replaces those items before checking which qualify for a discount. section 18.4
Listing 18.3 Seeding menu items during database reset
*** Support/Hooks.cs ***
[Binding]
public class Hooks(IDatabaseDriver databaseDriver,
MenuBackdoorDriver menuBackdoorDriver)
{
...
[BeforeScenario(Order = 0)]
public async Task ResetDatabase()
{
await databaseDriver.UpgradeSchemaIfNeeded();
await databaseDriver.EmptyDatabase();
SeedMenuData(); #A
}
private async Task SeedMenuData() #B
{
menuBackdoorDriver.SetMenuItems(
[
new MenuItemData { Name = "Margherita", Price = 7.99m,
Calories = 900, Vegetarian = true },
new MenuItemData { Name = "Pepperoni", Price = 9.99m,
Calories = 1200 },
new MenuItemData { Name = "Capricciosa", Price = 8.99m,
Calories = 1100 }
]);
}
...
}See how a database reset hook seeds menu items before scenario execution. section 18.4
