Using command line arguments to maven to set parallel and thread-count in testng suite XML

3,791 views
Skip to first unread message

Sud Ramasamy

unread,
Sep 26, 2014, 6:37:22 AM9/26/14
to testng...@googlegroups.com
I've got the following suite.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Smoke Suite">
  <test name="Test">
    <groups>      
   <run>
  <include name="smoke" />
   </run>    
    </groups>
    <packages>
      <package name="com.mine.*" />
    </packages>    
  </test>
</suite>


I'd like to be able to set the parallel and thread-count attributes values from commandline so I can control these values at the time of kicking off the tests.

I've tried all fo the following. But with no success - there is always only one thread that TestNG is spinning up:

pom.xml

                          <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<webdriver.impl.class>${webdriver.impl.class}</webdriver.impl.class>
<parallel>${parallel}</parallel>
<threadCount>${threadCount}</threadCount>
</systemPropertyVariables>
<suiteXmlFiles>
           <suiteXmlFile>src/test/resources/testng/testng-${suite}.xml</suiteXmlFile>
       </suiteXmlFiles>
</configuration>
</plugin>


Also tried this version of the pom.xml

                          <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
                                        <parallel>${parallel}</parallel>
        <threadCount>${threadCount}</threadCount>
<systemPropertyVariables>
<webdriver.impl.class>${webdriver.impl.class}</webdriver.impl.class>
</systemPropertyVariables>
<suiteXmlFiles>
            <suiteXmlFile>src/test/resources/testng/testng-${suite}.xml</suiteXmlFile>
        </suiteXmlFiles>
</configuration>
</plugin>

And passing in the values like so:

mvn clean integration-test -Dsuite=smoke -Dparallel=classes -DthreadCount=20

The suite variable is correctly getting substitute and TestNG is picking it up. But the parallel and threadCount properties are not being picked up in TestNG. My tests are still single-threaded.

Does anyone know what is the correct way to configure this. Or is this a bug in the failsafe/surefire plugin?

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Sep 26, 2014, 11:38:23 AM9/26/14
to testng-users
Can you try suitethreadpoolsize? I found this from testng documentation.

This is useful if you are running several suite files (e.g. "java org.testng.TestNG testng1.xml testng2.xml") and you want each of these suites to be run in a separate thread. You can use the following command line flag to specify the size of a thread pool:
java org.testng.TestNG -suitethreadpoolsize 3 testng1.xml testng2.xml testng3.xml
I guess threadcount is applicable only to classes,methods and tests.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

Shawn McCarthy

unread,
Sep 26, 2014, 12:19:58 PM9/26/14
to testng...@googlegroups.com
I don't believe you can use a suite xml file AND dynamically change the thread-count at run time. I have tried for days and couldn't figure it out (If there is a way, I am also interested).

Sud Ramasamy

unread,
Sep 26, 2014, 6:33:36 PM9/26/14
to testng...@googlegroups.com
Yep. I've been trying it too with different permutations and combinations and no luck. Looks like it is an unsupported configuration. Though it is not documented as such on the failsafe plugin page: http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#parallel.

I was hoping someone from the TestNG development team can confirm this. From scouring the internet I've come across atleast a handful of people who have posted their inability to get this working and no resolutions or confirmation that this was not supported were provided.

Shawn McCarthy

unread,
Sep 27, 2014, 1:04:59 AM9/27/14
to testng...@googlegroups.com
Here is what I use :

        <profile>
            <id>run-xxxxxxxx-smoke</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${maven.surefire-plugin.version}</version>
                        <configuration>
                            <parallel>methods</parallel>
                            <threadCount>${thread.count}</threadCount>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>failsafe-integration-tests</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
               </plugins>
            </build>
        </profile>

Sud Ramasamy

unread,
Oct 1, 2014, 10:11:50 PM10/1/14
to testng...@googlegroups.com
Thanks for the example. I've now ditched the suiteXml and instead have my tests configured in the pom.xml like you have it here. The suiteXml are still handy when launching the tests from with the IDE since they can be right-click and launched. But I don't need to support parameterizing the threadCount etc for that use case. So this approach works for me now.

Just wish there was some clearer documentation around this.

Shawn McCarthy

unread,
Oct 2, 2014, 9:49:38 AM10/2/14
to testng...@googlegroups.com
Likewise. If you do come up with a better solution, please post about it.

Thanks !

hossain...@gmail.com

unread,
Mar 27, 2019, 10:34:56 AM3/27/19
to testng-users
What you passing as runtime terminal parameter?
mvn clean integration-test -Dthread.count=1 
does not seem to work!
Reply all
Reply to author
Forward
0 new messages