Saturday, October 25, 2014


In this tutorial, We will see how to set maximum time for test case execution. If the test case takes more time than the specified time to finish then the TestNG will market it as failed.

To set maximum time for test case execution, we use timeOut attribute of @Test annotation.





TestNG timeOut Example


import org.testng.annotations.Test;

public class TimeOutTestCase {

 @Test
 public void LoginTest(){
  System.out.println("LoginTest test case is Passed");
 }
 
 // time in mulliseconds
 @Test(timeOut = 5000)
 public void WorkflowTest(){
  // System.out.println(" Ignore this test case.");
  try{
   Thread.sleep(6000);
  }catch(Exception e){
   System.out.println(e);
  }
 }
 
 @Test
 public void LogoutTest(){
  System.out.println("LogoutTest test case is Passed");
  System.out.println(" ");
 }

}

Output: