Running Tests in Parallel

In this topic, we will see how to run tests in parallel and how to control the thread count.

How to control parallelism? #

TestNG provides features to run tests in parallel. This parallelism and the thread count can be controlled from testng.xml.

Parallelism and thread count can be set at suite level or test level like below.

<suite name="Sample Test Suite" parallel="tests" thread-count="5">
<test name="Sample Test" parallel="tests" thread-count="5">

Types of parallelism #

TestNG supports the following parallelism:

  • methods run test methods in parallel in different threads. All dependent methods will be run in different threads, respecting the priority of tests.
  • tests run <test> tags in parallel in separate threads.
  • classes run test classes in parallel in separate threads, but test methods in those test classes will run in the same thread.
  • instances run instances of test methods/classes in parallel in different threads.

In the case of @DataProvider, the parallelism can be controlled using the attribute @DataProvider(parallel = true). By default, it is set to false and default dataprovider thread count is 10 which is considered only when parallel is enabled.

Now that you are familiar with running tests in parallel, in the next lesson, you will learn about grouping the tests.

Get hands-on with 1000+ tech skills courses.