Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @DataProvider present in different class

How to use @DataProvider that is present in a different class?

I have created a different package and I have defined data providers next to each test cases. Please share how I may to use that in a different class.

like image 921
Gaurav G Raj Avatar asked Dec 02 '22 11:12

Gaurav G Raj


1 Answers

You can use the dataProviderClass attribute of @Test:

public class StaticProvider {
  @DataProvider(name = "create")
  public static Object[][] createData() {
    return new Object[][] {
      new Object[] { new Integer(42) }
    };
  }
}

public class MyTest {
  @Test(dataProvider = "create", dataProviderClass = StaticProvider.class)
  public void test(Integer n) {
    // ...
  }
}

Check the documentation for more details.

like image 131
juherr Avatar answered Dec 06 '22 18:12

juherr