我在不同的类中有数据提供者,访问它是不同的 testng 类。我观察到,如果我不使用“静态”来返回它会抛出错误。我想知道这背后的逻辑是什么。请帮助我。
示例代码:
错误代码:
@DataProvider
public Object[][] testSumInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
正确代码:
@DataProvider
public static Object[][] testSumInput() {
return new Object[][] { { 5, 5 }, { 10, 10 }, { 20, 20 } };
}
创建数据提供者:
@DataProvider(name="dpProjectDetails")
public static Object[][] supplyProjectDetails(){
int noOfRows=CommonMethods.getRowCount(CommonMethods.XLPATH_PROJECT_DETAILS, CommonMethods.SHEET_PROJECT_DETAILS);
int noOfCell=CommonMethods.getCellCount(CommonMethods.XLPATH_PROJECT_DETAILS, CommonMethods.SHEET_PROJECT_DETAILS);
Object[][] projectDetails=new Object[noOfRows][noOfCell];
for(int row=1;row<=noOfRows;row++){
for(int cell=0;cell<noOfCell;cell++){
projectDetails[row-1][cell]=CommonMethods.getExcelData(CommonMethods.XLPATH_PROJECT_DETAILS, CommonMethods.SHEET_PROJECT_DETAILS, row, cell);
}
}
return projectDetails;
}
}
--> 访问它:
@Test(dataProvider="DPCustomerData", dataProviderClass=TDCreateCustomer.class)
public void createNewCustomer(String customerName,String custdescription){
TDCreateCustomer tdCreateCustomer=new TDCreateCustomer();
POCreateCustomer poCreateCustomer=new POCreateCustomer();
tdCreateCustomer.setCustomerName(customerName);
tdCreateCustomer.setDescription(custdescription);
poCreateCustomer.createNewCustomer(tdCreateCustomer);
}