Karate Parallel Testing - NextensArelB/SwaggerGenerationTool GitHub Wiki
Parallel testing is a type of testing that gives the ability for multiple tests to run at the same time as each other. Typically, all our karate tests run sequentially, as in one test at a time. This means that if you were to have a set of large karate tests. For example, 50 large separate scenarios, then Karate would run the first one, then once that one is complete run the second one, etc. This means the tests could run for an incredibly long time reducing efficiency and potentially slowing down other processes that are queued.
Using parallel testing we are able to run tests a lot faster. Using the previous example, depending on how many processes are chosen to run at one moment you could have multiple tests at the same time. Let's say we choose to have 10 tests running in parallel, then the time for the full suite of tests to run would be 5x shorter.
How do we set up Parallel testing in karate?
Luckily, setting up parallel testing is incredibly easy. The only prerequisite is that you have karate Jbang set up in your project as it gives the ability to run the tests in parallel. Use the following steps below to have the tests run in parallel:
- Locate the test.js file located in the root of your project (test.js is a required file for jbang. If the file is not present follow step 1a) 1a. Create a file called test.js in the root of your folder. Enter the following into the file: const karate = require('@karatelabs/karate'); karate.exec("");
- Find the line that has the following "karate.exec("");
- In between the quotation marks add the following -T 5
- -T is the command to make Karate run multiple threads, then the number determines how many threads to run at a time. With 5 it means that 5 karate tests will be running at the same time
When and where should I use parallel testing?
It should be used when there are many tests that need to be run, and the order that they are run in is not important. If the tests need to be run sequentially, for example, data is generated in one scenario that is used in the following scenarios then parallel testing would not be ideal. However, if the tests are fully independent of each other then this is a great way to speed up the tests and reduce execution time giving more time for other processes to run.
It is highly reccomended to have your test cases be created independently. As this reduces the chance of tests failing due to a failing dependency. But most importantly in the case of parallel testing it is required to have the tests be able to run independently.