19
Mar

TestNG methods parameterization by function returning object array

Following code snippet demonstrate Dataprovider function returning Object[].

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class MultipleGroups {

// You must need to mention data provider method name in Test method
@Test(dataProvider = “DataContainer”)
public void methodWithSingleAttribute(String name) {
System.out.println(“Hello “+ name);

}

// A data provider which will provide single value to a test method thrice.
@DataProvider(name = “DataContainer”)
public Object[] myDataProvider() {

// Passing 3 set of data and each set contains single value
Object data[] = new Object[4];
data[0] = “Java”;
data[1] = “Selenium”;
data[2] = “UFT”;
data[3] = “Winium”;
return data;
}

}