[我尝试使用Apache POI框架读取excel时,从testng中的dataprovider方法返回地图。
我写的代码是这个
@DataProvider(name="dp")
public Object[][] getExcelData(String testcaseID)throws IOException {
loadExcelDataFile();
Row row=sheet.getRow(returnMatchingRowData(testcaseID));
Row headerRow=sheet.getRow(0);
Map<String, String> map=new HashMap<String, String>();
for (int x=0; x<row.getLastCellNum(); x++) {
String key=headerRow.getCell(x).getStringCellValue();
String value=row.getCell(x).getStringCellValue();
map.put(key, value);
}
return new Object[][]{{map}};
}
@Test(dataProvider="dp")
public void test1(HashMap<String, String> map) throws IOException {
Object[][] ob=getExcelData("TC_001");
System.out.println(map.get("EmpName"));
System.out.println(ob.length);
}
我收到以下错误
org.testng.TestNGException:
Some DataProvider public java.lang.Object[][] com.orangehrm.meta.utils.ExcelUtils.getExcelData(java.lang.String) throws java.io.IOException parameters unresolved: at 0 type class java.lang.String
只需尝试返回地图,而无需声明对象,例如:
return map;