O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DataProvider or Factory

Many people get confused when they read about the DataProvider and @Factory annotations – what to use when? and what is better?

Let's take a look at both of their functionalities:

  • DataProvider: A test method that uses DataProvider will be executed a multiple number of times based on the data provided by the DataProvider. The test method will be executed using the same instance of the test class to which the test method belongs.
  • Factory: A factory will execute all the test methods present inside a test class using a separate instance of the respective class.

Let's create an example that shows the clear difference between these two.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required