How do you run tests in parallel in TestNG?
A) By setting the parallel attribute in the testng.xml file
B) By using the @Parallel annotation
C) By running multiple instances of TestNG
D) By setting the threads attribute in the @Test annotation
Answer:
A) By setting the parallel attribute in the testng.xml file
Explanation:
In TestNG, you can run tests in parallel by setting the parallel
attribute in the testng.xml
file. This attribute can be set at the suite, test, or method level, allowing you to specify how the tests should be executed in parallel.
For example:
<suite name="Suite" parallel="methods" thread-count="5">
<test name="Test">
<classes>
<class name="com.example.TestClass" />
</classes>
</test>
</suite>
In this example, the parallel="methods"
attribute ensures that the test methods are run in parallel with a maximum of 5 threads.