Reputation: 1990
I'm trying to pass a list of string as a DataProvider, here is my code:
@DataProvider(name="test-urls")
public Object[] testUrls(){
ArrayList<Object> data = new ArrayList<>();
// do something here to add elements
// i.e: data.add("test string 1");
return new Object[] {data};
}
Here is the test:
@Test(enabled = true, dataProvider = "test-urls")
public void test(String url) {
System.out.println("url: " + url);
}
It looks like the simple test fails. Can you please show me what is wrong with my code? Thank you
Upvotes: 0
Views: 1007
Reputation: 861
If you don't like an old-school DP style, it's worth to try a TestNG extension named test-data-supplier, which is an entity-driven DP. Then your sample will become as simple as:
@DataSupplier(name="test-urls")
public List<String> testUrls(){
return Arrays.asList("url1", "url2", "url3");
}
@Test(enabled = true, dataProvider = "test-urls")
public void test(String url) {
System.out.println("url: " + url);
}
Upvotes: 0
Reputation: 3273
You have to return Object[][]
or Object[]
or Iterator<Object[]
as per this
plus, in your case, receive with the same type
as ArrayList<string>
@DataProvider(name="test-urls")
public Object[][] testUrls(){
ArrayList<string> data = new ArrayList<>();
// do something here to add elements
// i.e: data.add("test string 1");
return new Object[][] {data};
}
@Test(enabled = true, dataProvider = "test-urls")
public void test( ArrayList<string> list) {
System.out.println(list);
}
Upvotes: 0