Testing / Cucumber Interview Questions
What is the difference between a Data Table and a Doc String in Cucumber?
Both let a single Gherkin step carry a larger chunk of structured data as an argument, but they're suited to different shapes of data: a Data Table for genuinely tabular, row-and-column data, and a Doc String for a single block of free-form text.
| Data Table | Doc String |
| Pipe-delimited rows and columns. | Triple-quote delimited block of text. |
| Received as a DataTable object (convertible to lists/maps). | Received as a plain String. |
| Best for multiple structured records, like a list of users. | Best for a single unstructured or semi-structured block, like a JSON payload or email body. |
# Data Table - multiple structured records Given the following products exist: | name | price | | Widget | 9.99 | # Doc String - a single block of text When the request body is: """ { "name": "Widget", "price": 9.99 } """
The practical rule of thumb is straightforward: reach for a Data Table when the data naturally has rows and columns, and reach for a Doc String when the data is a single cohesive block that wouldn't naturally split into rows at all.
More Related questions...