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 Factory test

  1. Create a new class by the name ExampleTest under the test.classes package and replace the following code in it:
    package test.classes;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    public class ExampleTest {
      private String param="";
      
      public ExampleTest(String param){
        this.param=param;
      }
      
      @BeforeClass
      public void beforeClass(){
        System.out.println("Before class executed.");
      }
      @Test
      public void testMethod(){
        System.out.println("The the parameter value is: "+param);
      }
    }

    The preceding class contains the testMethod and beforeClass methods. The constructor of the test class takes a String argument value. Both beforeClass and testMethod print a message onto console.

  2. Create a new class with ...

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