Overview

17 Dramatis personae patterns for clear naming of concepts

This chapter explains how BDD scenarios benefit from clear, descriptive naming for the business concepts they rely on. Drawing on the idea of dramatis personae, it argues that personas can represent users, data sets, configurations, messages, or other domain concepts that need to be referred to unambiguously in scenarios and automation. The central goal is to keep specifications readable for humans while still giving test code enough structure to create and identify the right objects and data.

The chapter then shows how small persona definitions can live directly in a feature file, either in a scenario or in a supporting block, so that the important data stays close to the behavior being described. This approach works well when the persona is simple, local to one feature, and useful for manual review, but it should be avoided when the data is large or would overwhelm the scenario. It also introduces the idea of naming user-facing messages so scenarios can assert meaning rather than brittle literal text, improving resilience when message wording changes or when localization is involved.

For larger or shared data sets, the chapter recommends moving personas outside the feature file and loading them from external sources such as CSV, XML, or JSON. It also shows how a templated approach can reduce duplication when many similar persona definitions differ only in a few details, letting domain experts curate reusable base data while scenarios specify just the variations they need. Across all these patterns, the emphasis is on preserving locality for essential facts, keeping scenarios understandable, and choosing the simplest data organization that still supports maintainable, expressive specifications.

Storing a named persona in a context object
Storing a named persona in a context object
Extending the custom parameter type to find the order number of a named order
Extending the custom parameter type to find the order number of a named order
Assert that correct localized message is generated
Assert that correct localized message is generated
Setting the context using a sales traffic external persona
Setting the context using a sales traffic external persona

Summary

  • It is often useful to give descriptive names to business concepts, data structures, or groups of entities. Every time we introduce a descriptive name, we are creating a persona.
  • Every persona has some unique aspect, making it useful for illustrating some part of the system’s expected behavior. Those unique aspects are specified in a persona definition.
  • Persona definitions range from a very simple naming of a single entity in one scenario all the way up to a complicated template containing a hierarchy of entities, shared among many feature files.
  • The In-place Persona pattern describes how simple persona definitions can be created as part of the feature file.
  • In-place personas can be created either in a feature file’s Background block (in which case they can be used by any scenario in the feature file) or in the specific Scenario that they are relevant to.
  • Almost every system provides some sort of text intended for users, such as validation messages, labels, prompts, and notifications—and that often needs to be localizable. The Message Persona pattern extends the In-place Persona pattern to help us write meaningful scenarios that handle human-readable text, without needing to provide the actual text.
  • Some persona definitions are too large to include in a feature file without harming readability. The External Persona pattern describes how a scenario can make use of a persona definition that is stored in an external file or repository.
  • External persona definitions can be used by any feature file that needs them.
  • Complicated persona definitions are usually created by domain experts to illustrate expected behavior. Therefore, many external persona definitions will express the expected results alongside the definition.
  • When multiple scenarios need to use similar persona definitions, the Templated Persona pattern can be useful to minimize the maintenance cost of creating a different persona definition for each scenario.
  • The Templated Persona pattern covers situations where a single persona definition is used as a template to be customized for various scenarios. This can be implemented using a templating library but can also be handled by hand-crafted step definitions.
  • External persona definitions are part of the system’s specification and so should be kept alongside, and versioned with, the feature files.

FAQ

What is a persona in this chapter’s BDD context?It is a meaningful name for a specific business concept, data set, user, or structured entity that scenarios need to refer to clearly and unambiguously.
Why are personas useful in behavior-driven development?They improve readability and communication by letting scenarios refer to business concepts by descriptive names instead of repeating verbose data or ambiguous technical details.
What is the In-place Persona pattern?It is the pattern of defining small persona definitions directly inside a feature file, either in a scenario or in a Background block, when the data is only needed within that feature.
When should a persona definition be kept inside the feature file?Keep it in the feature file when the persona is small, helps readers understand the scenario, and is only relevant to that single feature file.
What is the Message Persona pattern?It is a specialization of the In-place Persona pattern that lets scenarios refer to user-visible messages by a descriptive key instead of hard-coding the exact text.
Why use a message key instead of writing the full message text in a scenario?Using a key keeps scenarios stable when message wording changes and also supports localization, because the automation code can resolve the key to the correct language-specific text.
What is the External Persona pattern?It is the approach of storing large persona definitions in external files or repositories and loading them into scenarios when the full data set would be too large or reused across multiple feature files.
When is the External Persona pattern a better choice than an in-place definition?It is better when the persona is large, complex, not needed to understand the scenario in detail, or shared by multiple feature files.
What is the Templated Persona pattern?It is the practice of keeping a reusable external persona template and customizing it for a scenario by supplying a small set of variations, rather than creating many near-duplicate data sets.
What role do domain experts play in persona definitions?Domain experts often define and validate large or important personas, especially external or templated ones, so the data remains realistic, consistent, and aligned with business intent.

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


Close
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 Effective Behavior-Driven Development ebook for free
Close
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 Effective Behavior-Driven Development ebook for free