请教各位,testng,@DataProvider的名称为什么不能用于@Test啊?
从贴图的代码看,没看出有什么问题。
把全部代码贴出来
谢谢,我先继续调试看看
package com.ExcelDataTool;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author 李振7
* Created Time: 2017/11/9 下午4:38
* 根据filePath,fileName,caseName,获取excel中的数据,保存为HashMap<String, String>[]
*/
public class ExcelData {
public Workbook workbook;
public Sheet sheet;
public Cell cell;
int rows;
int columns;
public String filePath; //文件路径
public String fileName; //文件名,不包含文件后缀.xls
public String caseName; //sheet名
public ArrayList<String> arrkey = new ArrayList<String>();
String sourceFile;
/**
* @param fileName excel文件名
* @param caseName sheet名
*/
public ExcelData(String filePath, String fileName, String caseName) {
super();
this.fileName = fileName;
this.caseName = caseName;
this.filePath = filePath;
}
/**
* 获得excel表中的数据
*/
public Object[][] getExcelData() throws BiffException, IOException {
workbook = Workbook.getWorkbook(new File(this.setPath(filePath,fileName)));
sheet = workbook.getSheet(caseName);
rows = sheet.getRows(); //获取该sheet行数
columns = sheet.getColumns(); //获取该sheet列数
// 为了返回值是Object[][],定义一个多行单列的二维数组
HashMap<String, String>[][] arrmap = new HashMap[rows - 1][1];
// 对数组中所有元素hashmap进行初始化
if (rows > 1) {
for (int i = 0; i < rows - 1; i++) {
arrmap[i][0] = new HashMap<>();
}
} else {
System.out.println("excel中没有数据");
}
// 获得首行的列名,作为hashmap的key值
for (int c = 0; c < columns; c++) {
String cellvalue = sheet.getCell(c, 0).getContents();
arrkey.add(cellvalue);
}
// 遍历所有的单元格的值添加到hashmap中
for (int r = 1; r < rows; r++) {
for (int c = 0; c < columns; c++) {
String cellvalue = sheet.getCell(c, r).getContents();
arrmap[r - 1][0].put(arrkey.get(c), cellvalue);
}
}
return arrmap;
}
/**
* 获得excel文件的路径
* @return
* @throws IOException
* /Users/leeco/Desktop/letv/workspace/tools/src/resources/testData.xlsx
*/
public String setPath(String path, String fileName) throws IOException {
File directory = new File(".");
sourceFile = directory.getCanonicalPath() + path + fileName + ".xls";
return sourceFile;
}
}
import com.ExcelDataTool.ExcelData;
import com.dubbo.inter.info.IPromiseForOrderServiceTest;
import com.lemall.srd.order.promise.domain.common.PromiseVersion;
import jxl.read.biff.BiffException;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.StandardSampleSender;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.HashMap;
/**
* @author 李振7
* Created Time: 2017/10/20 上午11:10
*/
public class TestngTest {
public String filePath = "/src/resources/"; //文件路径
public String fileName = "com.lemall.srd.order.promise.api"; //文件名,不包含文件后缀.xls
public String caseName = "IPromiseForOrderService"; //sheet名
@DataProvider
public Object[][] Numbers() throws BiffException, IOException {
ExcelData e=new ExcelData("/src/ExcelData/","com.lemall.srd.order.promise.api", "IPromiseForOrderService");
return e.getExcelData();
}
@Test(dataProvider = "Numbers", dataProviderClass = TestngTest.class)
public void test(HashMap<String, String> data){
System.out.println(data.toString());
String orderNo = data.get("orderNo");
String operater = data.get("operater");
String channel = data.get("channel");
String operateId = data.get("operateId");
String version = data.get("version");
String Status = data.get("Status");
String Message = data.get("Message");
String Result = data.get("Result");
}
// @Test()
// public void testDubboInterface() {
// JavaSamplerContext arg0 = new JavaSamplerContext(new Arguments());
//
// IPromiseForOrderServiceTest TestForIPromiseForOrderService = new IPromiseForOrderServiceTest();
// TestForIPromiseForOrderService.DubboInterfaceInfoInitialization();
// TestForIPromiseForOrderService.setupTest(arg0);
// SampleResult sr = TestForIPromiseForOrderService.runTest(arg0);
// }
//
// @Test
// public void demo() {
// System.out.println("asdgdas23456789----------------=======================");
// }
}
代码在我这里运行正常