Parallel Test Execution using Karate DSL
Parallel Test Execution using Karate DSL
In this tutorial, we will run Automation Tests in parallel mode. Karate DSL has built-in parallel test execution. If the project is complex and has many Tests to run, running tests in parallel saves time.
This feature is useful during API performance testing. We can generate load on the services by launching tests with multiple threads concurrently.
Example
In this example, we will use Junit5 to run tests. Define a class with Karate Runner. Specify the path to the feature files. For example, if the features that need to be run are in the package
com.testingdocs.karate.demo
We can specify the path to the Runner:
Runner.path(“classpath:com/testingdocs/karate/demo”) .parallel(3);
In this example, we have specified 3 threads. The features would run with 3 threads concurrently.
Code Listing
package com.testingdocs.karate.demo; import com.intuit.karate.Results; import com.intuit.karate.Runner; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class MantisIssueRunner { @Test void testFeaturesInParallel() { Results results = Runner.path("classpath:com/testingdocs/karate/demo") .parallel(3); assertEquals(0, results.getFailCount(), results.getErrorMessages()); } }
Console
Run the tests with JUnit 5. We can see that the tests run with 3 threads concurrently. We can check the Karate Timeline test reports to check which thread has executed the features.
Karate version: 1.1.0
======================================================
elapsed: 9.08 | threads: 3 | thread time: 9.04
features: 6 | skipped: 0 | efficiency: 0.33
scenarios: 6 | passed: 6 | failed: 0
======================================================
Karate Automation Tutorials
Karate tool tutorials on this website can be found at:
More information on the tool: