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 – time test at test method level

  1. Add a new test class to the project created in the earlier section under the timetest package with the name TimeMethod:
  2. Add the following code to it:
    package test.timetest;
    
    import org.testng.annotations.Test;
    
    public class TimeMethod {
      @Test(timeOut=500)
      public void timeTestOne() throws InterruptedException{
        Thread.sleep(1000);
        System.out.println("Time test method one");
      }
    
      @Test
      public void timeTestTwo() throws InterruptedException{
        Thread.sleep(400);
        System.out.println("Time test method two");
      }
    
    }

    The preceding test class contains two test methods which print a message onto to the console on successful execution. Both also contain Thread.sleep method which pauses the test execution depending upon the ...

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