Karate Examples Table – Data‑Driven Testing Made Simple
Karate’s Examples table lets you run a single Scenario Outline against many data sets. This guide shows the exact syntax, a working Maven setup, how to verify the results, and common mistakes to avoid.
16 Sept 2025, 22:37 UTC

What You Get With Karate’s Examples Table
Karate lets you run a single Scenario Outline against many data sets. The Examples table is resolved at compile time, so each row becomes a separate scenario that appears in the JUnit report and the Karate HTML report.
Why Use Examples?
If you need to validate the same behaviour with different inputs—such as user credentials, request payloads, or query parameters—embedding the data in an Examples table keeps the feature file short and avoids duplicating steps.
Concrete Worked Example
Below is a minimal Maven project that demonstrates a data‑driven login test. The feature file contains an Examples table with two user accounts.
1. Maven Setup
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Place this in pom.xml and run mvn test.
2. Feature File (src/test/resources/login.feature)
Feature: User login
Scenario Outline: Validate login credentials
Given url 'https://api.example.com/login'
And request { username: '<username>', password: '<password>' }
When method post
Then status 200
And match response == { success: true }
Examples:
| username | password |
| alice | secret1 |
| bob | secret2 |
Notice the angle brackets around the placeholders. If you omit them, Karate will treat the values as literal strings and the test will fail.
3. Verify the Output
- In the Maven console you should see two test executions, each with a display name that includes the resolved data (e.g.,
Validate login credentials [alice, secret1]). - Open
target/karate-reports/index.htmlto see separate sections for each iteration, showing the request body and the response.
Common Pitfalls & Limits
1. Embedding Large Data Sets
Karate expands the Examples table at compile time, so a table with 1,000 rows creates 1,000 separate scenarios. This can bloat the test report and slow down execution. For bulk data, consider externalizing the source with karate.read('classpath:data.json') and using a Scenario that loops over the array.
2. No Nested Tables
Karate does not support tables inside the Examples table. If you need complex objects, embed JSON strings or load them from an external file.
3. Type Coercion
All values from the Examples table are treated as strings. If a numeric value is needed, cast it explicitly in the step, e.g., int age = Integer.parseInt('<age>').
4. Special Characters
Values containing pipe symbols (|), quotes, or backslashes must be escaped or quoted in the table. Otherwise the Gherkin parser will misinterpret the table boundaries.
5. Mixing with Background
When a Background section is present, it runs before every scenario, including each iteration of the Examples table. Ensure that any setup performed in Background is idempotent or reset between iterations.
When to Use Examples vs. Scenario
If the test logic is identical and you only vary input data, Scenario Outline with Examples is the cleanest choice. If the logic itself changes—for instance, you need to test different authentication flows—use separate Scenario blocks.
Takeaway
Karate’s Examples table is a powerful, compile‑time data‑driven mechanism that keeps feature files concise. Keep the table small, escape special characters, and remember that all values are strings. For large or dynamic data sets, externalize the data and drive the test with a loop instead of an Examples table.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.