Site icon TestingDocs.com

Parallel Test Execution using Karate DSL

Overview

In this tutorial, we will run Automation Tests in parallel mode. Parallel Test Execution in Karate DSL is in-built. If the project is complex and has many Tests to run, then running tests in parallel saves time.

This feature is useful during performance testing of the APIs. We can generate load on the services by launching tests with multiple threads concurrently.

Parallel Test Execution

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:

https://www.testingdocs.com/karate-automation-tool-tutorials/

More information on the tool:

https://github.com/intuit/karate

Exit mobile version