Running Tests in Parallel
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">
TestNG supports the following parallelism:
methodsrun test methods in parallel in different threads. All dependent methods will be run in different threads, respecting the priority of tests.
testsrun <test> tags in parallel in separate threads.
classesrun test classes in parallel in separate threads, but test methods in those test classes will run in the same thread.
instancesrun 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.