Overview

14 Prop cupboard patterns for managing input test data

The chapter focuses on practical ways to manage input test data in BDD without cluttering scenarios with incidental details. It frames these techniques as “props” kept in a prop cupboard: reusable test data that supports the scenario while keeping the business-facing text concise and essential. The main idea is that default data should be chosen deliberately by the team, documented centrally, and reused consistently so automation remains readable, maintainable, and easy to update.

It begins with simple defaults, showing how a centralized set of domain defaults prevents hard-coded values from spreading through the codebase. When scenarios need a typical object or object hierarchy, a default instance factory can create a ready-made object that callers may then tweak. As object structures become more complex, an object mother takes over by constructing customized default objects and allowing variations through fluent, builder-like methods. This shifts customization responsibility into shared support code, reducing duplication and making default construction more expressive.

The chapter then broadens the same idea to other forms of test data. Custom parameter types help scenarios speak the domain’s language while hiding conversion logic, and data table accessors separate table parsing from step definitions, especially when columns are optional or schemas evolve. For assertions, table comparison helpers provide atomic checks with rich diff output, keeping verification logic compact and diagnostic. Finally, the validation tester pattern shows how default instances and scenario outlines can describe data validation rules clearly by focusing each scenario on only the changed fields, which makes both specification and automation easier to understand and extend.

Summary

  • The Domain Default pattern provides a way to define default test data in a shared location to provide consistency across the test suite and avoid the maintenance issues of having hard-coded constants spread throughout the codebase.
  • The Default Instance pattern shows how to avoid code duplication when building simple default objects and hierarchies using factory methods.
  • Modifying default instances for specific test cases can be done by the test case if the factory method returns a mutable instance.
  • When returning a mutable instance is not possible use the Object Mother pattern to create a builder that accepts customization instructions before constructing the instance to be returned.
  • Fluent interfaces offer a clear, readable mechanism for chaining together builder customization instructions.
  • Although enums can sometimes be used to directly model simple domain terminology, the more powerful technique described in the Terminology Promotion pattern uses custom parameter types to provide a more flexible modeling mechanism.
  • Data tables are a concise and clear way to include complicated data in a step. Interacting programmatically with tabular representations is hard to read and maintain, so apply the Data Table Accessor pattern to parse the content of data tables into a data structure created expressly to model that data.
  • It is not always essential to describe every available property of a data structure in every step. Ensure that the code parsing a data table, and the data structure that models the data, can handle optional properties and provide appropriate default values.
  • Data tables can also be useful to express complicated expectations of a scenario. Comparing the actual and expected outcomes, when expressed as tables, is a powerful way support atomic assertions, but use the Data Table Assertion pattern to ensure complete diagnostics are provided across the full comparison.
  • Testing data validation can get exponentially more complicated as the number of interacting attributes increase. Apply the Validation Tester pattern to spread data validation testing across multiple scenarios, each of which targets a specific rule that governs a relationship between a subset of the available attributes.

FAQ

What is the purpose of the Prop Cupboard pattern language in BDD automation?It provides a structured way to manage input test data, especially default values, so scenarios stay focused on behavior while the automation code centrally handles incidental data details.
How does the Domain Default pattern improve test data management?It centralizes default test values in one place, promoting consistency across the codebase and making defaults easier to maintain and update.
When should you use a Default Instance instead of hard-coded values in step definitions?Use a Default Instance when multiple steps need a pre-defined object or object hierarchy, and you want to avoid repeating construction logic and scattered default values.
What problem does the Object Mother pattern solve?It helps create customized default objects and object hierarchies by moving object construction and customization logic into a reusable builder-like class.
Why are builders useful for test data when objects are immutable?Because if the returned object cannot be modified after creation, the builder can accept customization instructions up front and build the final object with the requested changes applied.
What is Terminology Promotion in the context of BDD?It is the use of custom parameter types to support domain-specific terminology directly in step expressions, keeping scenarios readable and aligned with business language.
How does the Data Table Accessor pattern make data table handling easier?It separates conversion logic from step definitions, supports optional columns, and makes code more robust by using typed data structures instead of raw cell access.
What is the advantage of using Data Table Assertion instead of manual comparison logic?It performs a single atomic assertion that compares expected and actual table data, while also producing detailed diagnostics that show all differences.
How does the Validation Tester pattern simplify testing complicated validation rules?It breaks validation into separate scenarios for each rule aspect and uses default instances plus targeted overwrites to reduce duplication and clarify intent.
Why is centralization emphasized throughout the Prop Cupboard patterns?Centralization reduces duplication, improves consistency, makes future changes easier, and helps the automation code document agreed-upon defaults and data-handling decisions.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Effective Behavior-Driven Development ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Effective Behavior-Driven Development ebook for free