Enable and Verify Parallel Test Execution in Karate 1.5+
Cut your Karate test suite runtime by enabling parallel execution. Follow this step‑by‑step guide to configure, verify, and recover from issues with the built‑in parallel feature in Karate 1.5+.
02 Jul 2026, 04:06 UTC

Desired Outcome
Cut the total runtime of a Karate test suite by leveraging multiple CPU cores while keeping results deterministic and reproducible.
Prerequisites
- Karate 1.5.0 or newer in your project dependencies.
- JUnit 5 or TestNG test runner configured (Karate’s own runners are thin wrappers).
- All feature files must be independent – no shared mutable state (static fields, global files, external services that are not isolated).
- Java 8+ (Karate’s parallel implementation relies on the standard Java thread pool).
- Build tool: Maven or Gradle. The examples below use Maven; the same flags apply to Gradle.
Focused Procedure
- Determine the number of worker threads.
Use the number of logical CPU cores minus one as a safe default. For a 4‑core machine, set
karate.parallel=3. If memory is tight, choose a lower value. - Configure the flag in the build tool.
For Maven, add the system property to the
mvn testcommand or to thepom.xml:mvn test -Dkarate.parallel=3Or in
pom.xml:<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <systemPropertyVariables> <karate.parallel>3</karate.parallel> </systemPropertyVariables> </configuration> </plugin> </plugins> </build>For Gradle, set the property in the test task:
tasks.test { systemProperty 'karate.parallel', '3' } - Run the suite.
Execute the build command. Karate will spawn the specified number of worker threads and distribute feature files among them.
- Verify parallel execution.
Check the console output for lines prefixed with
Paralleland thread identifiers. Example snippet:Parallel: Running feature /path/to/feature1.feature on Thread-0 Parallel: Running feature /path/to/feature2.feature on Thread-1 ...Also compare total elapsed time between
-Dkarate.parallel=3and-Dkarate.parallel=1. The former should finish noticeably faster if tests are independent. - Optional: Enable verbose thread logging.
Use
-Dkarate.log=TRACEto see thread‑local context details, useful for debugging race conditions.
Expected Checks
- Console shows
Parallelprefixes with thread names. - Test reports (JUnit XML, TestNG XML) contain the same number of test cases as before.
- No flaky failures appear that were absent in sequential runs.
- Memory usage stays within acceptable limits (monitor
jcmd VM.native_memory summaryif needed).
Recovery Options
- Revert to sequential execution. Set
-Dkarate.parallel=1or remove the property. - Reduce thread count. If out‑of‑memory errors occur, try
-Dkarate.parallel=2or the default (CPU - 1). - Isolate shared resources. Move any shared file writes or static state into a setup/teardown that runs per thread or use thread‑local containers.
- Use environment variables. For CI pipelines, export
KARATE_PARALLELand let the runner pick it up automatically.
Practical Checklist
| Step | Action | Expected Result |
|---|---|---|
| 1 | Run with -Dkarate.parallel=4 | Console shows four distinct Thread-* entries. |
| 2 | Compare timings | Parallel run < 50% of sequential if tests are independent. |
| 3 | Check for flaky failures | Same failure rate as sequential. |
| 4 | Monitor memory | Peak usage < 2× baseline of sequential run. |
Limitations
- Only supported in Karate 1.5.0+. Earlier releases lack built‑in parallel support.
- Test cases that modify shared files or rely on static state will still fail nondeterministically.
- External services (e.g., databases) must provide isolation per thread or use transaction rollbacks.
- Large suites may hit the Java thread‑pool limit; adjust
-Dkarate.max-threadsif necessary.
Conclusion
Enabling Karate’s parallel mode is a one‑line change to your build configuration, but it requires disciplined test design. With proper isolation and a sensible thread count, you can halve or better the total execution time of large API test suites.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.