When validation rules interact across several fields, one large scenario can obscure what each rule requires. The validation tester pattern clarifies the specification by giving each aspect of a complicated rule its own scenario. section 14.7
A practical approach:
- Use specific test data, scenario outlines, and default instances to express and automate validation checks. section 14.7
- As the number of interacting attributes grows, separate checks so each scenario targets a particular rule or relationship. section 14.8
A multi-field rule
For customer contact details, test the rule that US customers must provide a state separately: a US customer without one is rejected, while a US customer with one and a non-US customer without one are accepted. section 14.7
Listing 14.33 Specific scenario for a multi-field validation
*** Features/CustomerCollection.feature ***
Rule: Customers must supply acceptable contact details when placing an
➥order for customer-collection
Scenario Outline: Contact details supplied
...
Scenario Outline: State is mandatory for US customers
Given a customer has chosen to collect their order
When the customer provides valid contact details, but
| country | state |
| <country> | <state> |
Then the contact details are <result>
Examples:
| description | country | state | result |
| state missing for US | US | none | not accepted |
| state provided for US | US | CA | accepted |
| state optional, non-US | France | none | accepted |See the scenario outline and examples for the country-and-state validation rule. section 14.7
