我正在使用 TestNG DataProvider 读取一个 datapool.xls 文件,该文件包含 1017 个测试用例和一个名为 ReadData 的类中的 214 个列。
然后,我将 214 个字符串参数传递到名为 EnterData 的单独类中的 @Test 注释中。
@Test(dataProvider="autodata", dataProviderClass = ReadAutoData.class)
public void autoentry(String Quote, String Garage_Zip, etc...) {
我在 @Test 中创建了一个 for 循环,只执行某些迭代(比如 1-10)的操作,总共只输入 10 个测试用例就可以工作。我的问题是,在运行结束时,它仍然显示“运行的总测试数:1017”,而不仅仅是因为 for 循环而实际执行任何操作的 10 个。
// Start for loop for entering auto policies
for (int a = start; a <= end; a++)
{
if (quote == a)
{
System.out.println("Tier = " + Tier);
}
}
我意识到为什么它将运行的测试总数显示为整个数据池,因为它在技术上传入并运行了数据池中的所有内容,我只是无法弄清楚如何让它只显示实际运行的测试数量。
基本上,我正在寻找一种将 @Test 注释本身放入 for 循环中的方法,可能吗?...
编辑:
这是我当前在 ReadAutoData 类中读取数据池的代码:
@DataProvider(name = "autodata")
public static Object[][] autodata() {
Object[][] arrayObject = getExcelData("C:/dev/AutoDP.xls","NON-COMBO-DP");
return arrayObject;
}
/**
* @param File Name
* @param Sheet Name
* @return
*/
public static String[][] getExcelData(String fileName, String sheetName) {
String[][] arrayExcelData = null;
try {
FileInputStream fs = new FileInputStream(fileName);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sh = wb.getSheet(sheetName);
int totalNoOfCols = sh.getColumns();
int totalNoOfRows = sh.getRows();
arrayExcelData = new String[totalNoOfRows-1][totalNoOfCols];
for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
return arrayExcelData;
}
编辑2:
这是迄今为止我在 1017 个测试用例中所处的位置,我现在通过在我的 for 循环开头添加以下内容来显示 1007 个跳过:
// Start for loop for entering auto policies
for (int a = start; a <= end; a++)
{
if (quote < start) throw new SkipException("Testing skip.");
if (quote > end) throw new SkipException("Testing skip.");
if (quote == a)
{
System.out.println("Starting Iteration = " + Quote);
但是,它仍然显示 1017 测试运行。