java - Skip Certain Test Iterations Using TestNG DataProvider -


i'm using testng dataprovider read datapool.xls file contains 1017 test cases , 214 columns in class called readdata.

i pass 214 string parameters @test annotation in separate class called enterdata.

@test(dataprovider="autodata", dataproviderclass = readautodata.class) public void autoentry(string quote, string garage_zip, etc...) { 

i have created loop within @test perform actions ceratin iterations (say 1-10), work entering 10 test cases in total. problem @ end of run still shows "total tests run: 1017" instead of 10 did because of loop.

// start loop entering auto policies (int = start; <= end; a++) {     if (quote == a)     {                system.out.println("tier = " + tier);                            }  } 

i realize why shows total number of tests run being entire datapool because technically passed in , ran through in datapool, can't figure out how have show number of tests ran.

basically, i'm looking way put @test annotation in loop, possibly?...

edit:

here current code reading datapool in 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];          (int i= 1 ; < totalnoofrows; i++) {              (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 i'm @ far out of 1017 test cases, have gotten show 1007 skips adding following @ beginning of loop:

// start loop entering auto policies     (int = start; <= 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, still showing 1017 tests run.

the way can achieve understand how testng framework executes.

which means:

  1. skipexception not solution count test cases, if skipped.
  2. the number of tests number of rows returned @dataprovider method.

the solution return correct number of test cases method annotated @dataprovider:

public class readautodata {     private static int indexfrom;     private static int indexto;      @dataprovider(name = "autodata")     public static object[][] autodata() {         // should cache static variable         object[][] arrayobject = getexceldata("c:/dev/autodp.xls","non-combo-dp");           return java.util.arrays.copyofrange(arrayobject, indexfrom, indexto);     }      public class<?> autodatawithinrange(int from, int to) {         indexfrom = from;         indexto   = to;          return readautodata.class;     } }  @test(dataprovider="autodata", dataproviderclass = readautodata.autodatawithinrange(0, 10)) public void autoentry(string quote, string garage_zip, etc...) { 

this work if not running test concurrently. if are, can still use small modification using threadlocals.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -