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 ...

Get TestNg Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.