Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

How to fail a testNG test if it doesn’t get executed within a specified time?

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!”);
}

Leave a Reply

Your email address will not be published. Required fields are marked *