How to Succeed with Junit and Timeout?
1 answer
Try the following:
Execute logic on the thread, sleep and check if the thread is alive.
@Test
public void fineForFiveSeconds() throws InterruptedException {
Thread thread = new Thread() {
@Override
public void run() {
foo.doforever();
}
};
thread.start();
//Let the current thread sleep (not the created thread!)
Thread.sleep(5000);
assertTrue(thread.isAlive());
}
+3
source to share