Groups & DataProviders.

193 views
Skip to first unread message

Shreyas Chaudhari

unread,
May 3, 2013, 12:28:33 AM5/3/13
to testng...@googlegroups.com
I have a method named 'method1'. To this method I provide 2 different sets of data via DataProvider. In this case my testsuite.xml is -

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

testsuite.xml - 

<suite name="TestNgExperiments" parallel="tests" thread-count="1">

<test name="test name1">
<parameter name="a" value="abc">
<classes>
<class name="com.abc.method1">
</class>
</classes>
</test>

<test name="test name2">
<parameter name="a" value="pqr">
<classes>
<class name="com.abc.method1">
</class>
</classes>
</test>

</suite>

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

Now, if I want to use Groups and if 'method1' falls under say a group 'sampleGroup1' then my testsuite.xml looks like -

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

<suite name="TestNgExperiments" preserve-order="true">

<test name="Test1">
<groups>
<run>
<include name="sampleGroup1"/>
</run>
</groups>
<classes>
<class name="com.abc" />
<methods>
<include name="method1"/>
</methods>
</classes>
</test>
</suite>

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

If I make my method - 'method1' data driven using DataProvider, still I can use only 1 set of data i.e. say <parameter name="a" value="abc">. 

I would like to know, how can I call the same 'method1' multiple times using Groups using different Datasets?

Can I have something like -

<include name="method1" dataset="ds1"/>
<include name="method1" dataset="ds2"/>

Matthias Rothe

unread,
May 3, 2013, 9:55:06 AM5/3/13
to testng...@googlegroups.com
Hi Shreyas,

I think you got the concepts of providing data via parameters defined in the testng.xml and providing data via data providers mixed up. These two concepts are hugely different from each other. With parameters you always have just one test method invocation. With data providers you have as many as there are Object[] values returned from the data provider. While parameters are defined within the testng.xml file, as you correctly did, data providers are never defined there, but rather via the @Test annotation arguments dataProviderClass and dataProvider. The data provider itself is then implemented as a public static method on the given dataProviderClass and needs to either return Object[][] or Iterator<Object[]>. Within these you can define as many data sets as you like.

If you want to spare yourself all that hassle and would like to have an easy option for loading data from external sources available, please take a look at the TestNG Data Binding framework. To get started using it have a look at the JavaDocs at http://testngdatabind.sf.net/apidocs.

I hope this helps.

Kind regards,
Matthias
Reply all
Reply to author
Forward
0 new messages