Reputation: 438
As in the title, is it possible to run test methods within the same test class in parallel to speed up the testing process?
Currently using Junit but planning to switch to TestNG eventually so feel free to use either for your answer.
Using the tests in the context of Functional Testing (Selenium) and since the tests check the production server there would be no issue to using multiple threads to speed up the testing process.
From my search so far I have established that with TestNG I can run different classes(containing test methods) in parallel, what I wanted to know is if I can run the methods inside the same test class in a parallel and not serialized way.
Upvotes: 0
Views: 1925
Reputation: 526
The parallelization in TestNG depends on the mode specified in your suite.
<suite name="My suite" parallel="methods" thread-count="5">
Will make 5 methods at the same time run in paralell, as long as they don't depend on each other. Dependend methods will wait until all dependencies has been runned before they are started. Other modes are "tests", "classes" and "instances".
If you want different threading for different tests inside the same xml you can add the parellel property to the test tag instead e.g.
<suite name="default" thread-count="4">
<test name="asa" parallel="methods">
<classes>
<class name="multiThreaded"/>
<class name="multiThreaded"/>
</classes>
</test>
<test name="asa" parallel="false">
<classes>
<class name="singleThreaded"/>
<class name="singleThreaded"/>
</classes>
</test>
</suite>
See http://testng.org/doc/documentation-main.html#parallel-tests for more information
Upvotes: 3