all. I have existing xml file testng suite. I want to use it in gradle task and set thread count programmatically
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="UiTests">
<test name="UiTests" preserve-order="true">
<packages>
<package name="tests.web">
<exclude name="tests.web.performance"/>
</package>
</packages>
</test>
</suite>
In gradle task I use useTestNG method and set threadCount parameter
useTestNG{
suites("src/testы/suites/UiTests.xml")
threadCount 2
setParallel("methods")
}
But it doesn't works - count of threads get from xml file, so how I can set thread count programmatically?
The threadcount value specified in the TestNG suite xml file has the final say. That is why even though you try to set it via the TestNGOptions in your gradle test task, it doesnt take effect.
To get past this, you need to do the following:
org.testng.IAlterSuiteListener
wherein you alter the thread count either at theXmlSuite
level (<suite>
level) or at theXmlTest
level (<test>
level)@Listeners
annotation (or) via your suite xml (or) via Serviceloaders. For more details read my blog post hereHere's how all of this looks like in action.
Test class looks like this
Test listener looks like this
Suite xml looks like this
The gradle test task looks like this
Here's the output
You can now control the thread count by passing in an appropriate via the JVM argument
-Dthreads