Category:
TestNG
We can use the timeOut attribute of @Test annotation. The value assigned to this timeOut attribute will act as an upperbound, if test doesn’t get executed within this time frame then it will fail with timeOut exception.
@Test(timeOut = 1000)
public void timeOutTest() throws InterruptedException {
//Sleep for 2sec so that test will fail
Thread.sleep(2000);
System.out.println(“Will throw Timeout exception!”);
}