0

Basically i want to run a test which will set certain value for a variable which i am going to use in another test(dependent). But the first method has DataProvider for over 30 iterations. I do not want to run it 30 times but only very first time.

Is it possible that i can terminate execution of the first method just after first iteration. Not sure but i believe Test Listeners can handle this but don't know how. Anyone having any idea , please share your thoughts.

Thanks

Hanendra
  • 31
  • 2

1 Answers1

0

You can modify the code of the dataprovider method to pass in a Method argument to it. This will be automatically be injected with the method about to invoked by testng. Place a if condition on the method name to return an Object[][] with size of 1.

@DataProvider(name = "provider")
  public Object[][] dp(Method m) {
      if(m.getName().equals("oneData")) {
          //Create and return object[][] SIZE 1
      } else {
         //Normal dump of data
      }
  }

Refer to this -- http://testng.org/doc/documentation-main.html#dependency-injection

Grasshopper
  • 8,908
  • 2
  • 17
  • 32