我想将参数传递给@test 以使用不同的数据多次运行。所以我正在使用@DataProvider,它正在重新调整二维对象数组。我有一维字符串,所以首先我将它转换为二维数组,然后为对象赋值。. 但得到以下例外。
public class DtaProvider {
public static String patchfileName = null;
public static String[] patchsplit = null;
public static String temp= null;
public int number = 0;
@DataProvider(name = "getData")
public Object[][] createData() {
patchfileName = "hi,how,are,you";
patchsplit = patchfileName.split(",");
Object[] arr = patchsplit ;
System.out.println(arr.length);
for(int i=0;i<arr.length;i++){
System.out.println(arr[i].toString());
}
Object[][] data = new Object[arr.length][arr.length];
for (int x = 0; x < arr.length; x++){
data[x][x] = arr[x];
}
return data;
}
@Test(dataProvider="getData")
public void DownloadPatch(String patchfileNamea ){
try{
System.out.println("Name is b"+patchfileNamea);
}
catch (Exception e){
org.testng.Assert.fail("Failed to Download Patch to NgDriver " + e.getMessage());
}
}
}
TestNG] Running:
C:\Users\Mohan Raj S\AppData\Local\Temp\testng-eclipse-1472908796\testng-customsuite.xml
4
hi
how
are
you
FAILED: DownloadPatch
org.testng.TestNGException:
The data provider is trying to pass 4 parameters but the method testclasses.DtaProvider#DownloadPatch takes 1
at org.testng.internal.Invoker.injectParameters(Invoker.java:1257)
请帮助我如何将参数顺序传递给我的@test 方法?