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 – running TestNG programmatically

Perform the following steps to run TestNG programmatically:

  1. Create a new Java project named TestngCodeProject with the following structure as shown in the following screenshot:
    Time for action – running TestNG programmatically
  2. Create a new class named SampleTest under the test.sample package and add the following code to it:
    package test.sample;
    
    import org.testng.annotations.Test;
    
    public class SampleTest {
      @Test
      public void testMethodOne(){
        System.out.println("Test method One");
      }
      
      @Test
      public void testMethodTwo(){
        System.out.println("Test method two");
      }
    
    }

    The previous code contains a simple test class with two test methods. These test methods print ...

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