Chapter 14: Prop cupboard patterns for managing input test data
This introduction explains why scenario automation needs ways to supply input test data without cluttering scenarios with incidental details.
After this chapter you will be able to
- Essential Scenario Data. Explain why scenarios should omit data that does not directly illustrate the expected behavior, even though automation may still need that data to perform its actions.
- Incidental scenario test data. Distinguish details a scenario needs to specify from valid default values the automation must still choose.
- Team agreed centralized defaults. Explain why the team should agree on default test values and define them in one place for reuse across step definitions.
- Customizable default test objects. Explain why step definitions use a factory method to create a default instance, then change only the properties a scenario constrains.
- Customization inside the generator. Explain why repeated changes to default test objects can be moved from step definitions into a generator, and how the caller specifies the desired changes.
- Complex orders and shared defaults. Describe why a more complex object hierarchy may call for a standalone Object Mother, and how its customization interface should relate to existing testing defaults.
- Custom domain terminology conversion. Describe why inch-based pizza sizes need a custom parameter type and how the Terminology Promotion pattern uses it instead of repeating conversions in step definitions.
- Separate Typed Table Representation. Justify using a separate test-automation data class and conversion logic rather than representing table rows directly with a production entity.
- Optional Columns and Defaults. Describe how the pattern handles omitted columns without requiring every scenario table to specify every value.
- Single Table Assertion. Explain how the Data Table Assertion pattern replaces repeated property checks in a Then step with one comparison of expected table data against actual results.
- Complete Difference Diagnostics. Describe what a failing table assertion reports and why seeing all differences helps diagnose a failure.
- Validation Examples Without Duplication. Explain why putting every field value in a validation scenario outline becomes hard to read and maintain, and how a default instance lets examples specify only the values relevant to a rule.
- Applying Scenario Data Overwrites. Describe how automation applies the values specified by a validation scenario to a default instance, including the role of the When step and FillInstance.
- Clear Multi Field Validation. Describe how to illustrate a rule involving multiple fields by changing multiple properties of a default instance, and explain when separate scenarios preserve clarity.
What it builds on
- Keep your scenarios BRIEF (chapter 7) · The BRIEF essential principle for keeping scenarios focused.
- Document the essence of the behavior (chapter 7) · Keeping scenarios focused on the essence of the behavior
- Step definitions (chapter 12) · Step definitions that supply values during scenario automation
- Expressions and parameters (chapter 12) · Cucumber expression placeholders and step definition parameters
- Custom parameter types (chapter 12) · Custom parameter types in scenario automation
- The principles (chapter 7) · The BRIEF principles for formulated scenarios
- Atomic assertion (chapter 12) · The SUITABLE atomic assertion principle
- Scenario outlines and examples tables (chapter 8) · Scenario outlines and examples tables provide the format for varying cases.
Section by section
Introduction
This introduction explains why scenario automation needs ways to supply input test data without cluttering scenarios with incidental details.
- Essential Scenario Data: Explain why scenarios should omit data that does not directly illustrate the expected behavior, even though automation may still need that data to perform its actions.
Why it matters: It explains why readable scenarios and executable automation need different amounts of data. - Prop Cupboard Purpose: Describe what the Prop Cupboard pattern language is for and what the theatrical analogy means in this context.
Why it matters: The analogy gives the chapter's data-management patterns a shared purpose.
Key terms: essential principle, incidental details, automation code, Prop Cupboard pattern language, input test data, scenario’s context, props
14.1 Domain Default pattern for managing default test data
This section explains how the Domain Default pattern keeps incidental test data out of scenarios while making automation defaults consistent and easy to change.
- Incidental scenario test data: Distinguish details a scenario needs to specify from valid default values the automation must still choose.
Why it matters: It keeps scenarios focused on the behavior they illustrate without leaving the automation short of required data. - Team agreed centralized defaults: Explain why the team should agree on default test values and define them in one place for reuse across step definitions.
Why it matters: A shared default avoids repeated choices and lets the team update one definition instead of hunting through the codebase. - Defaults class as documentation: Describe how a readable defaults class records the team's choices and how it can be organized if the collection grows.
Why it matters: Recording decisions where they are used helps the documentation stay aligned with the automation code.
Key terms: default test data, scenario, incidental detail, Domain Default pattern, DomainDefaults, default test values, step definitions, DomainDefaults class, documentation, whole entities
14.2 Default Instance pattern: use defaults, but…
This section explains how the Default Instance pattern creates customizable test data from shared defaults without duplicating object construction across step definitions.
- Customizable default test objects: Explain why step definitions use a factory method to create a default instance, then change only the properties a scenario constrains.
Why it matters: It makes each scenario’s special requirements easier to see and reduces repeated setup code. - Composed default object hierarchies: Describe how default instances can represent larger object structures by using smaller default instances, and why the generator should remain clear.
Why it matters: The same approach can cover complex test data without hiding what the team considers normal. - User-facing test data structure: Distinguish the structure of default test data from the production code’s internal data structure.
Why it matters: Test setup can use terms meaningful to readers without copying internal storage structures. - Immutable instance customization: Distinguish customization of a mutable default instance from the alternative when the returned instance is immutable.
Why it matters: It clarifies when the simple generate-then-modify approach applies.
Key terms: Default Instance pattern, factory method, DomainDefaults, step definition, default instance, generator function, object structure, outside perspective, test data, denormalized structures
14.3 Object Mother pattern: generate complicated test data structures
This section explains how Object Mothers build customized default test data and object hierarchies, and when their added abstraction is worthwhile.
- Customization inside the generator: Explain why repeated changes to default test objects can be moved from step definitions into a generator, and how the caller specifies the desired changes.
Why it matters: Putting recurring customization in one place makes step definitions easier to read and maintain. - Complex orders and shared defaults: Describe why a more complex object hierarchy may call for a standalone Object Mother, and how its customization interface should relate to existing testing defaults.
Why it matters: A builder for orders is useful when it expresses real variations without discarding the team’s shared defaults. - Fluent configuration method chains: Explain how a fluent Object Mother interface works and identify its benefit and cost relative to a traditional interface.
Why it matters: Fluent calls can make test-data instructions easier to scan, but readability is not free of trade-offs. - Mutable and deferred construction: Distinguish modifying a mutable object during configuration from collecting instructions and constructing the result in Build.
Why it matters: The builder’s internal design must suit whether its result can be modified and when construction work should occur. - Judicious test data abstraction: Justify when not to create a general-purpose Object Mother for test data with many uncommon variations.
Why it matters: Avoiding unnecessary abstraction can leave unusual test cases clearer than a highly configurable builder would.
Key terms: Object Mother, Default Instance pattern, overwrite instructions, object structure, Domain default pattern, fluent interfaces, configuration instruction methods, traditional interface style, mutable, immutable
14.4 Terminology Promotion pattern: expressing domain-specific data
This section shows how custom parameter types let scenarios use business terminology while keeping conversion logic out of individual step definitions.
- Built-in parameter conversion: Explain how Reqnroll can pass a quoted {string} value to a step definition parameter typed as PizzaSize, and how an explicit {PizzaSize} placeholder differs.
Why it matters: This explains why the original step definition works and why a different conversion is needed for inch-based sizes. - Custom domain terminology conversion: Describe why inch-based pizza sizes need a custom parameter type and how the Terminology Promotion pattern uses it instead of repeating conversions in step definitions.
Why it matters: Centralized conversion lets many steps accept the language used in scenarios without duplicating conversion code. - Business language in scenarios: Justify using stakeholders’ pizza-size terminology in scenarios even when the existing order-service enum uses different terms.
Why it matters: Readers can distinguish meaningful business wording from implementation terms that cannot immediately be changed.
Key terms: {string}, PizzaSize, built-in parameter conversion, {PizzaSize}, Terminology Promotion pattern, custom parameter type, {pizza-size}, Business language principle, domain-specific language, order service
14.5 Data Table Accessor pattern: handling data table parameters
This section explains how the Data Table Accessor pattern turns scenario data tables into typed test data while keeping conversion and optional-column handling out of step definitions.
- Raw Data Table Limitations: Explain why working directly with data table cells makes step definitions cumbersome and fragile.
Why it matters: These problems explain why the pattern separates data table handling from a step’s main job. - Separate Typed Table Representation: Justify using a separate test-automation data class and conversion logic rather than representing table rows directly with a production entity.
Why it matters: A table-focused data class keeps scenario input readable without forcing it into the production model. - Optional Columns and Defaults: Describe how the pattern handles omitted columns without requiring every scenario table to specify every value.
Why it matters: Optional columns let scenarios state only the input values that matter to the example. - Reusable Data Table Conversion: Distinguish the section’s built-in and custom options for converting data tables before step definitions use their values.
Why it matters: Reusable conversion reduces repeated table-handling code across step definitions.
Key terms: data tables, step definitions, optional columns, typed data structure, MenuItemData, MenuItem, conversion logic, optional types, DomainDefaults, default values
14.6 Data Table Assertion pattern: asserting with data tables
This section explains how a single data-table assertion can simplify Then steps and make failures easier to diagnose.
- Single Table Assertion: Explain how the Data Table Assertion pattern replaces repeated property checks in a Then step with one comparison of expected table data against actual results.
Why it matters: One comparison keeps step definitions easier to read and maintain. - Complete Difference Diagnostics: Describe what a failing table assertion reports and why seeing all differences helps diagnose a failure.
Why it matters: A full diff helps distinguish an isolated bad item from a broader problem. - Selective Comparison Behavior: Explain why converting the table to objects and using ordinary equality may be insufficient, particularly when the table omits a property.
Why it matters: An omitted column should not cause a failure for a property the scenario did not ask to verify.
Key terms: Data Table Assertion pattern, Then step, CompareToSet, atomic assertion, diff, expected result, actual result, CreateSet, diff calculator, omitted column
14.7 Validation Tester pattern: specifying and automating data validation
This section explains how the Validation Tester pattern uses default instances and focused scenarios to specify and automate data validation rules without duplicating test data.
- Validation Examples Without Duplication: Explain why putting every field value in a validation scenario outline becomes hard to read and maintain, and how a default instance lets examples specify only the values relevant to a rule.
Why it matters: Focused examples make validation rules easier to read and maintain as fields and cases multiply. - Applying Scenario Data Overwrites: Describe how automation applies the values specified by a validation scenario to a default instance, including the role of the When step and FillInstance.
Why it matters: This connects a concise, readable validation example to the data the automated test actually uses. - Clear Multi Field Validation: Describe how to illustrate a rule involving multiple fields by changing multiple properties of a default instance, and explain when separate scenarios preserve clarity.
Why it matters: A validation rule involving several fields is only useful as a specification if their relationship remains visible.
Key terms: Validation Tester pattern, default instance, scenario outline, examples table, When step, step definition, overwrites, FillInstance, data table, multi-field validation
14.8 Summary
Where this is used later
- Challenges of using real databases for test execution (chapter 18) · The need to manage input test data for scenarios.
Concepts explained in this chapter
- object motherA test-data construction pattern that provides methods for creating default objects or object hierarchies customized for particular tests.
- data table accessor patternThe Data Table Accessor pattern separates conversion of data table values into typed data structures from the step definitions that consume them.
- domain default patternA pattern for defining default test data in a shared location to promote consistency and avoid maintenance issues from scattered hard-coded constants.
- validation tester patternA pattern that clarifies the specification and testing of complex data validations by separating validation-rule aspects into scenarios.
- data table assertion patternA pattern for comparing tabular actual and expected outcomes while providing complete diagnostics across the comparison.
- default instance patternA test-data pattern that provides factory methods for creating default objects or object hierarchies that can be customized for a scenario.
- terminology promotion patternA behavioral-test automation pattern that uses centralized custom parameter conversions to represent domain-specific terminology in specifications.
- default instanceAn object created with agreed default values that can be customized for a scenario.
- parameter typeA user-defined parameter type that matches captured text and converts it into a value for a step definition.
- built-in parameter conversionBuilt-in parameter conversion is automatic conversion from a matched Cucumber expression value to the declared type of a step definition method parameter.
- domain-specific dataDomain-specific data is information represented using terminology and value forms meaningful within a particular business domain.
- A Pattern LanguageA structured collection of interrelated patterns that helps identify an appropriate pattern for a specific context.
- essential principleA scenario-writing principle that removes details that do not contribute directly to illustrating the behavior of a rule.
- fluent interfaceAn API design style in which chained calls or expressions read as a sequence of operations.
- documentationDocumentation is recorded information describing a system and its behavior for reference and maintenance.
- maintainabilityMaintainability is the ease with which software can be understood, modified, corrected, or enhanced.
- CompareToSetA Reqnroll method that compares data-table rows with a collection of objects and reports differences.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
