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

Time for action – using DataProvider with Factory

Create a new class by the name DataProviderConsTest under the test.classes package and replace the following code in it:

package test.classes; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; public class DataProviderConsTest { private int param; @Factory(dataProvider="dataMethod") public DataProviderConsTest(int param){ this.param=param; } @DataProvider public static Object[][] dataMethod(){ return new Object[][]{ {0}, {1} }; } @Test public void testMethodOne(){ int opValue=param+1; System.out.println("Test method one output: "+ opValue); } @Test public void testMethodTwo(){ int opValue=param+2; System.out.println("Test method ...

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