liveBook · Manning

Built-in parameter conversion

As explained in Effective Behavior-Driven Development

Built-in parameter conversion is automatic conversion from a matched Cucumber expression value to the declared type of a step definition method parameter.

A step expression can capture a value as one type while its method accepts another. When Reqnroll invokes the step definition, it compares those types and attempts a built-in conversion. section 14.4

Built-in conversions support:

  • Basic types such as int, decimal, and DateTime. section 14.4
  • Enums, matched without regard to case, and GUIDs. section 14.4

Pizza size as an enum

A step can capture the quoted value "Large" with {string} and pass it to a method parameter of type PizzaSize. Alternatively, use {PizzaSize} in the expression and write large without quotes. If scenarios use inch measurements instead of enum values, built-in enum conversion no longer fits; convert the value manually or define a custom parameter type. section 14.4

How Effective Behavior-Driven Development covers it

How deep it goes
Explains type matching and supported conversions, but defers non-enum domain values to manual or custom conversion.
Examples
Uses pizza-size scenarios to contrast string-to-enum conversion, an enum placeholder, and inch-based values.
What it assumes
Assumes familiarity with Cucumber expression placeholders and step-definition method parameters.
What you can do after
Apply Reqnroll's built-in conversion by matching a Cucumber expression value to a supported method parameter type.
How it connects
Connects Cucumber expressions and step definitions with enums, basic types, and GUIDs.

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.