Cucumber Data Tables
The CUCUMBER_DATA_TABLE mode — Gherkin data tables are passed as Cucumber DataTable objects, giving you the full Cucumber DataTable API for conversions and POJO mapping.
Source: examples/common-use-cases/example-2 on GitHub.
What this demonstrates
@Gherkin2JUnitOptions(dataTableParameterType = CUCUMBER_DATA_TABLE)switches the mode- Step methods receive
DataTableinstead ofList<XxxParam> - The generator emits a
createDataTable(String tableLines)helper that parses pipe-delimited text blocks - You must provide a
getTableConverter()method somewhere in the class hierarchy - Access to the full Cucumber API:
asList(),asMap(),asMaps(), POJO mapping - Requires the
cucumber-javadependency
When to pick this mode
| Aspect | LIST_OF_OBJECT_PARAMS (default) | CUCUMBER_DATA_TABLE |
|---|---|---|
| Parameter type | List<GeneratedParam> | DataTable |
| Type safety | Compile-time (typed fields) | Runtime (string-based) |
| POJO mapping | Automatic (generated classes) | Manual (DataTableTypeRegistry) |
| Dependencies | None | cucumber-java |
| Best for | New projects, compile-time safety | Migrating from Cucumber, complex conversions |
Generated call site
myCartContainsTheFollowingProducts(createDataTable("""
|name |qty|unit price|
|Wireless Headphones|1 |59.99 |
|Coffee Beans 1kg |3 |12.50 |
"""));
POJO mapping with DataTableTypeRegistry
registry.defineDataTableType(new DataTableType(
Product.class,
(Map<String, String> row) -> new Product(
row.get("name"),
Integer.parseInt(row.get("qty")),
Double.parseDouble(row.get("unit price"))
)
));
// Inside the step method:
List<Product> products = dataTable.asList(Product.class);
Run it
cd examples/common-use-cases/example-2
mvn test