liveBook · Manning

Step definition

As explained in Effective Behavior-Driven Development

Automation code associated with a behavior-specification step that performs or checks the step’s behavior.

A step definition is reusable automation code that runs in response to a scenario step. It connects the step’s wording to an action or check, helping turn scenarios into executable tests. section 12.3.2 section 12.6

A scenario automation tool matches each step’s text against registered expressions, then calls the corresponding definition. A definition is often a named method, though some tools use anonymous methods. New scenarios can reuse definitions already written for other scenarios. section 12.3.2

Matching must identify exactly one definition:

  • No match produces an undefined-step error; more than one match produces an ambiguous-step error, and execution terminates. section 12.3.5 section 12.6
  • Alternatives, optional text, parameters, and custom parameter types make expressions harder to reason about. Prefer multiple simple expressions over complicated matching logic that is difficult to debug. section 12.3.5

Changing an image color

A step definition can match a color-change step using either a color name, such as yellow, red, or blue, or a hexadecimal RGB value. Custom parameter types can represent these alternatives. section 12.3.5

Figure 12.4 Conceptual approach for matching step text to step definition

See the conceptual matching flow from step text to a registered definition. section 12.3.5

How Effective Behavior-Driven Development covers it

How deep it goes
Explains registration and matching, including expression complexity, custom parameter types, and undefined or ambiguous matches.
Examples
Uses customer authentication and image color changes to illustrate step definitions and parameter matching.
What you can do after
Diagnose undefined or ambiguous steps and simplify expressions that make matching difficult to debug.
How it connects
Connects step definitions to scenario automation, glue code, registration expressions, and custom parameter types.

Also explained in

Compare how 3 books explain step definition →

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.