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 – DataProvider in different class

  1. Open Eclipse and add two new classes with the names DataProviderClass and TestClass to the Java project created earlier.
  2. Add the following code to TestClass:
    package test.dataprovider;
    
    import org.testng.annotations.Test;
    
    public class TestClass {
      
      @Test(dataProvider = "data-provider",dataProviderClass=DataProviderClass.class)
      public void testMethod(String data) {
        System.out.println("Data is: " + data);
      }
    
    }

    The preceding test class contains a test method which takes one argument as input and prints it onto the console when executed. The DataProvider to provide parameter values to a test method is defined by giving the name of the DataProvider using the DataProvider attribute while using Test annotation. ...

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