liveBook · Manning

Validation tester pattern

As explained in Effective Behavior-Driven Development

A pattern that clarifies the specification and testing of complex data validations by separating validation-rule aspects into scenarios.

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

How Effective Behavior-Driven Development covers it

How deep it goes
Combines specific test data, scenario outlines, and default instances, then separates multi-attribute rules into focused scenarios.
Examples
Tests required contact details and the US-specific relationship between country and state.
What you can do after
Understand how to split interacting validation rules into scenarios that target individual attribute relationships.
How it connects
Connects validation testing with scenario outlines, default instances, and data tables.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.