Step Parameters
How quoted values in Gherkin steps become typed Java method parameters with automatic type inference.
Source: examples/getting-started/example-2 on GitHub.
What this demonstrates
- Each quoted value in a step (
"59.99","3","true") becomes a method parameter - The generator infers the parameter type from the value's shape
- Parameter slots are marked in the method name with
$p1,$p2,$p3placeholders - Multiple parameters in a single step
Type inference rules
| Quoted value | Inferred type |
|---|---|
"true" / "false" | Boolean |
Integer literal (e.g. "3") | Integer (or Long if too large) |
Decimal literal (e.g. "59.99") | Double |
Single character (e.g. "Y") | Character |
Everything else (e.g. "Wireless Headphones") | String |
The feature file
Scenario: Adjusting a single item
Given my cart contains "Wireless Headphones" with quantity "1" and unit price "59.99"
When I change the quantity to "3"
Then the cart subtotal should be "179.97"
And the discount applied is "false"
And the discount badge shows "Y"
The generated step methods
void myCartContains$p1WithQuantity$p2AndUnitPrice$p3(String p1, Integer p2, Double p3);
void iChangeTheQuantityTo$p1(Integer p1);
void theCartSubtotalShouldBe$p1(Double p1);
void theDiscountAppliedIs$p1(Boolean p1);
void theDiscountBadgeShows$p1(Character p1);
Each "…" token in the original step text becomes a parameter; the $p1, $p2, … placeholders in the method name mark where each parameter belongs. Identical step text under different keywords (Given / When / Then / And / But) reuses the same method.
Run it
cd examples/getting-started/example-2
mvn test