dataProvider作为数据提供者只能返回Object[][]和Iterator<Object[]>类型的数据 直接看代码:
public class UserInfo {
@DataProvider public Object[][] getUserInfo1(){ List<Object> item=new ArrayList<Object>();; User user=new User(); user.setName("1037350"); user.setPass("abc123"); item.add(user); Object[][] result=new Object[item.size()][]; for(int i=0;i<item.size();i++){ result[i]=new Object[]{item.get(i)}; } return result; } @DataProvider public Iterator<Object[]> getUserInfo2(){ List<User> item=new ArrayList<User>();; User user=new User(); user.setName("1037350"); user.setPass("abc123qeqwwe"); item.add(user); List<Object[]> dataToBeReturned = new ArrayList<Object[]>(); for (User userData : item) { dataToBeReturned.add(new Object[] { userData } ); } return dataToBeReturned.iterator(); }
}
public class HelloTestNg extends UserInfo{
@Test(dataProvider="getUserInfo2", public void printUser(User user ){ System.out.println(user.getName()+":"+ user.getPass()); } }