I'm using the TestNG DataProvider to read a datapool.xls file that contains 1017 test cases and 214 columns in a class called ReadData.
I then pass the 214 String parameters into an @Test annotation in a separate class called EnterData.
@Test(dataProvider="autodata", dataProviderClass = ReadAutoData.class)
public void autoentry(String Quote, String Garage_Zip, etc...) {
I have created a for loop within @Test to only perform the actions for ceratin iterations (say 1-10), which does work by only entering 10 test cases in total. My problem is that at the end of the run it still shows "Total tests run: 1017" instead of only the 10 that actually did anything because of the for loop.
// Start for loop for entering auto policies
for (int a = start; a <= end; a++)
{
if (quote == a)
{
System.out.println("Tier = " + Tier);
}
}
I realize why it shows the total number of tests run as being the entire datapool because it technically passed in and ran through everything in the datapool, I just can't figure out how to only have it show the number of tests that actually ran.
Basically, I'm looking for a way to put the @Test annotation itself in the for loop, possibly?...
Edit:
Here is my current code for reading the datapool in the ReadAutoData Class:
@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;
}
Edit 2:
Here's where I'm at so far out of the 1017 test cases, I have gotten it to now show 1007 Skips by adding the following at the beginning of my for loop:
// 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);
however, it is still showing 1017 Tests run.