Jai
Jai

Reputation: 319

Testng does not count dataprovider tests individually

Here is my dataprovider

@DataProvider(name = "arrayBuilder")
public Object[][] parameterTestProvider() {
    //Code to obtain retailerIDList
    String[] retailerIDArray = retailerIDList.toArray(new String[retailerIDList.size()]);
assertEquals(1295, retailerIDList.size(), "Expected 1295, found " + retailerIDList.size() + " docs");
    return new Object[][] {{retailerIDArray}};
}

and this is my test

@Test(dataProvider = "arrayBuilder", invocationCount = 1, threadPoolSize = 1)
public void getRetailer(String[] retailerIDList) {

    for (String retailer_ID : retailerIDList) {
        //Code that uses the retailerID 
 }

When I execute this test, TestNG output lists "getRetailer" as the only test. I have 1295 records returned by dataprovider and I want 1295 tests to be reported. What am I missing?

Upvotes: 1

Views: 2593

Answers (2)

Shamik
Shamik

Reputation: 1609

Please use this, it should work. You need to return array of objects where each row is a row of data that you want to use for a test. Then only it will come in the report. What you were doing was sending it an array so it was treating it as a single test.

    @DataProvider(name="provideData")
    public  Iterator<Object[]> provideData() throws Exception
    {
        List<Object[]> data = new ArrayList<Object[]>();
        String[] retailerIDArray = retailerIDList.toArray(new String[retailerIDList.size()]);
        assertEquals(1295, retailerIDList.size(), "Expected 1295, found " + retailerIDList.size() + " docs");
        for(String retailerID : retailerIDArray ){

            data.add(new Object[]{retailerID});

        }

        return data.iterator(); 

    }

@Test(dataProvider = "provideData")
public void getRetailer(String retailerIDList) {

    for (String retailer_ID : retailerIDList) {
        //Code that uses the retailerID 
    }
}

For more Information please go through the documentation here

Upvotes: 1

tim-slifer
tim-slifer

Reputation: 1088

DataProviders alone, while iterating for each data set, will only yield a cumulative result for the test instead of a result for each iteration.

Try using a Test Factory alongside the DataProvider for an individual result for each iteration of the test.

http://testng.org/doc/documentation-main.html#factories

Upvotes: 0

Related Questions