A scenario says a customer orders a Margherita pizza to qualify for a coupon. The pizza’s size does not affect that behavior, so the scenario leaves it out. Automation still needs a size to place the order. If each step definition supplies its own hard-coded value, those choices can drift apart and become difficult to change. section 14.1 section 14.8
The Domain Default pattern puts agreed default test values in one shared, readable location. A step definition uses the named default instead of embedding a value such as "Medium". This keeps incidental test data out of the scenario while making the automation’s choice visible and consistent. section 14.1 section 14.0
Listing 14.3 Class to keep the defaults and modified step definition
*** Support/DomainDefaults.cs ***
public static class DomainDefaults
{
public const string PizzaSize = "Medium"; #A
}
*** StepDefinitions/OrderingStepDefinitions.cs ***
[Given("the customer has placed an order containing a {string} pizza")]
public void GivenTheCustomerHasPlacedAnOrderContaining(string pizzaName)
{
var order = ...
order.AddItem(pizzaName, DomainDefaults.PizzaSize); #B
...
}The step definition uses DomainDefaults.PizzaSize instead of repeating "Medium". The shared name shows where to find or change the default. section 14.1
Choose defaults deliberately:
- Agree on values as a team, especially where business rules make some combinations invalid. section 14.1
- Keep decisions in the readable defaults code rather than relying on a separate document that can become outdated; add a code comment when a decision needs more explanation. section 14.1
- Introduce the shared location when the first default is needed, rather than waiting for hard-coded values to spread. section 14.1
A domain default supplies an incidental value; it does not make that value a rule of every scenario. Keep behaviorally important details explicit, and use shared defaults for the data needed to set up the rest. section 14.1 section 14.0
