0

I have a class with @Factory(dataProvider = "dp") at constructor. How can I obtain that class inside data provider?

class Test {

   @Factory(dataProvider = "dp")
   public Test(int i) {
      //... some code
   }

   @DataProvider
   public static Object[][] dp(ITestContext context, Method method) {
       // need to get currently created class by factory
       // method is null here
       // not found any way to obtain this class from test context
   }

}

In this example I can use hardcoded class name, but in real worl data provider is in parent class (or just separated class)

Sergey Irisov
  • 468
  • 4
  • 7

1 Answers1

2

Just do the following:

class Test {

   @Factory(dataProvider = "dp")
   public Test(int i) {
      //... some code
   }

   @DataProvider
   public static Object[][] dp(ConstructorOrMethod com) {
       Class<?> testClass = com.getConstructor().getDeclaringClass();
   }

}
juherr
  • 5,640
  • 1
  • 21
  • 63