title: Skip Certain Test Iterations Using TestNG DataProvider
body: <p>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.</p>
  
  <p>I then pass the 214 String parameters into an @Test annotation in a separate class called EnterData.</p>
  
  <pre><code>@Test(dataProvider="autodata", dataProviderClass = ReadAutoData.class)
  public void autoentry(String Quote, String Garage_Zip, etc...) {
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>// Start for loop for entering auto policies
  for (int a = start; a &lt;= end; a++)
  {
      if (quote == a)
      {       
          System.out.println("Tier = " + Tier);                       
      } 
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Basically, I'm looking for a way to put the @Test annotation itself in the for loop, possibly?...</p>
  
  <p>Edit:</p>
  
  <p>Here is my current code for reading the datapool in the ReadAutoData Class:</p>
  
  <pre><code>@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 &lt; totalNoOfRows; i++) {
  
              for (int j=0; j &lt; 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;
  }
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>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:</p>
  
  <pre><code>// Start for loop for entering auto policies
      for (int a = start; a &lt;= end; a++)
      {
          if (quote &lt; start) throw new SkipException("Testing skip.");
          if (quote &gt; end) throw new SkipException("Testing skip.");
  
          if (quote == a)
          {
  
              System.out.println("Starting Iteration = " + Quote);
  </code></pre>
  
  <p>however, it is still showing 1017 Tests run.</p>