testng
public classTestRegister { @Test(dataProvider="datas") public voidtest1(String,url,String username,String pwd){ Map<String, String> params = new HashMap<String, String>(); params.put("username", username); params.put("pwd", pwd); System.out.println(HttpUtils.doPost(params,url)); } @DataProvider publicObject[][] datas(){ //取出固定列的数据 int[] rows = {1,2,3,4,5,6}; int[] cols = {2,3,4}; Object[][] datas = ExcelUtil.readExcel2("C:\\Users\\Administrator\\Desktop\\register.xls",rows,cols); returndatas; } }
ExcelUtil.readExcel2
public static Object[] [] readExcel2(String url,int[] rows,int[] cols){ Object[] [] datas = newObject[rows.length][cols.length]; //获取Workbook对象 try{ File file = newFile(url); Workbook workBook =WorkbookFactory.create(file); //获取sheet 对象 Sheet sheet = workBook.getSheet("Sheet1"); DataFormatter formatter = newDataFormatter(); //获取行 for(int i = 0;i < rows.length ;i++){ Row row =sheet.getRow(rows[i]); for(int j = 0;j < cols.length;j++){ Cell cell =row.getCell(cols[j], Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); String value =formatter.formatCellValue(cell); datas[i][j] =value; } System.out.println(); } } catch(IOException e) { e.printStackTrace(); } returndatas; }
表格
HttpUtils.doPost以及所需要jar包参考:https://www.cnblogs.com/ychun/p/15612428.html