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 – the DataProvider test

  1. Create a new class by the name DataProviderClass under the test.classes package and replace the following code in it:
    package test.classes;
    
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class DataProviderClass {
    
      @BeforeClass
      public void beforeClass(){
        System.out.println("Before class executed");
      }
    
      @Test(dataProvider="dataMethod")
      public void testMethod(String param){
        System.out.println("The parameter value is: "+param);
      }
    
      @DataProvider
      public Object[][] dataMethod(){
        return new Object[][]{
            {"one"},
            {"two"}
        };
      }
    }

    The preceding class contains the testMethod and beforeClass methods. testMethod takes a String argument and the ...

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