使用testNG框架在dataprovider中获取异常

问题描述 投票:0回答:1

[我尝试使用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
java apache-poi testng testng-dataprovider
1个回答
0
投票

只需尝试返回地图,而无需声明对象,例如:

return map;
© www.soinside.com 2019 - 2024. All rights reserved.