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 JUnit and TestNG tests together

  1. Open the previously created Java project in Eclipse.
  2. Create a new class named TestngSampleTest under the package test.sample.testng and add the following code to it:
    package test.sample.testng;
    
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;
    
    public class TestngSampleTest {
      @BeforeMethod
      public void beforeMethod(){
        System.out.println("Testng before method");
      }
      
      @Test
      public void testMethod(){
        System.out.println("Testng test method");
      }
      
      @AfterMethod
      public void afterMethod(){
        System.out.println("Testng after method");
      }
    
    }
  3. Create a new file named junit-testng-test.xml and paste the following code to it:
    <suite name="Junit ...

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