I am trying to create a testNG dataprovider method which will return an array of objects of a custom class from my project. This array is a one dimensional array and I dont want to return two dimensional array from this dataprovider method. Please suggest, should Dataprovider always return a 2D array(not less than or more than 2D). If yes then I need help in the following line:
return new Object[][]{{user[0]},{user[1]},{user[2]},{user[3]}}
Can we write this line of code in any better way because if in future this array expands will have more than 4 elements than it we will have to edit this full function, Can't we use list etc?
Below is the code that I am currently using:
@DataProvider(name = "credentialsProvider", parallel=false)
public static Object[][] credentialsProvider() throws Exception {
User[] user=new User[4];
user[0]=new User(UserTypes.AGENCY_MANAGER,1);
user[1]=new User(UserTypes.AGENT,1);
user[2]=new User(UserTypes.AGENCY_MODERATOR,1);
user[3]=new User(UserTypes.EW_ECS_AGENCY_MANAGER,1);
return new Object[][]{{user[0]},{user[1]},{user[2]},{user[3]}};
};
}