Setting DataProvider thread count from command line

1,268 views
Skip to first unread message

Greg Hicks

unread,
Aug 28, 2017, 4:37:40 AM8/28/17
to testng-users
Hi All

I have been working  on using the parallel threads in testng and have been able to get the test to work from a suite xml file. I have attached the files for reference.

Its just a thought at the moment, could I use something like this to do the same from maven surefire?

mvn -Dtest=parallelDataProvider#testParallel -Dparallel="methods" -Ddata-provider-thread-count="6" test

If feedback indicates consensus to implement, then I will work with the group devs towards the solution.

regards


Greg Hicks

Senior Software Engineer and QA Test Engineer

Melbourne Australia
WebBrowser.java
BaseTest.java
WebSession.java
parallelDataProvider.xml
parallelDataProvider.java

Krishnan Mahadevan

unread,
Aug 30, 2017, 12:08:54 PM8/30/17
to testng...@googlegroups.com

Greg,

 

I didn’t quite get as to what you are trying to achieve.

Being able to control the data provider thread count is a pretty straight forward thing that you can do with TestNG.

 

For doing it you would be leveraging org.testng.IAlterSuiteListener

 

Here’s a sample that shows how to do this:

 

A sample listener could look like below:

 

import org.testng.IAlterSuiteListener;

import org.testng.xml.XmlSuite;

 

import java.util.List;

 

public class SuiteAlterer implements IAlterSuiteListener {

 

    @Override

    public void alter(List<XmlSuite> suites) {

        int count = Integer.parseInt(System.getProperty("threadcount", "3"));

        XmlSuite suite = suites.get(0);

        suite.setDataProviderThreadCount(count);

    }

}

 

Here’s a test class:

import org.testng.TestNG;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

 

public class TestClassSample {

    public static void main(String[] args) {

        System.setProperty("threadcount", "20");

        TestNG testng = new TestNG();

        testng.setTestClasses(new Class<?>[]{TestClassSample.class});

        testng.addListener(new SuiteAlterer());

        testng.run();

    }

 

    @Test(dataProvider = "dp")

    public void testMethod(int i) {

        System.err.println("Running with the value (" + i + ") on thread [" + Thread.currentThread().getId() + "]");

    }

 

    @DataProvider(name = "dp", parallel = true)

    public Object[][] getData() {

        int size = 20;

        Object[][] objects = new Object[size][1];

        for (int i = 0; i < size; i++) {

            objects[i] = new Object[]{i};

        }

        return objects;

    }

}

 

Here’s the output:

 

Running with the value (18) on thread [29]

Running with the value (0) on thread [11]

Running with the value (2) on thread [13]

Running with the value (16) on thread [27]

Running with the value (10) on thread [21]

Running with the value (15) on thread [26]

Running with the value (3) on thread [14]

Running with the value (7) on thread [18]

Running with the value (19) on thread [30]

Running with the value (8) on thread [19]

Running with the value (9) on thread [20]

Running with the value (17) on thread [28]

Running with the value (5) on thread [16]

Running with the value (11) on thread [22]

Running with the value (14) on thread [25]

Running with the value (4) on thread [15]

Running with the value (6) on thread [17]

Running with the value (12) on thread [23]

Running with the value (1) on thread [12]

Running with the value (13) on thread [24]

 

===============================================

Command line suite

Total tests run: 20, Failures: 0, Skips: 0

===============================================

 

 

Process finished with exit code 0

 

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Greg Hicks

unread,
Sep 2, 2017, 2:29:51 AM9/2/17
to testng-users
Hi Krishnan

You're on the right track, thanks for the info.

If we need to pass the value in via the command line as I had shown, it looks like pom properties can be helpful to this work.

Otherwise the IAlterSuiteListener seems to be the right solution for this to be run via a CI server.

Cheers

Greg Hicks

unread,
Sep 2, 2017, 3:25:19 AM9/2/17
to testng-users
PS could we update the data provider parallel = true value?

⇜Krishnan Mahadevan⇝

unread,
Sep 6, 2017, 3:20:31 AM9/6/17
to testng...@googlegroups.com
​For that you should be implementing org.testng.IAnnotationTransformer2 and wiring this listener in.​

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.

Greg Hicks

unread,
Sep 6, 2017, 4:12:50 AM9/6/17
to testng...@googlegroups.com
Krishnan

Thanks for the pointer.. I will give it a try and let you know how I go with it

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/UW1Ydj0_wMc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
regards

Greg

kool79

unread,
Nov 27, 2017, 4:20:08 PM11/27/17
to testng...@googlegroups.com
You use incorrect property name. Valid name does not contain hyphens:
-Ddataproviderthreadcount="6"



--
Sent from: http://testng.1065351.n5.nabble.com/testng-users-f3.html
Reply all
Reply to author
Forward
0 new messages