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 Test annotation on Class

  1. Open Eclipse and create a Java project with the structure shown in the following screenshot:
    Time for action – using Test annotation on Class
  2. Create a new Java class with the name SameClassDataProvider and copy the following code to it:
    package test.dataprovider;
    
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class SameClassDataProvider {
      @DataProvider(name = "data-provider")
      public Object[][] dataProviderMethod() {
        return new Object[][] { { "data one" }, { "data two" } };
      }
    
      @Test(dataProvider = "data-provider")
      public void testMethod(String data) {
        System.out.println("Data is: " + data);
      }
    }

    The preceding test ...

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