3

Basically I need the opposite behaviour of the @Test(timeout=X) annotation.

The problem I want to solve is to detect in some way that the method never ends (as a right behaviour). I am assuming that if the method didn't stop after X seconds, I am sure "it will never end".

Thanks!

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Michel
  • 163
  • 1
  • 2
  • 7

1 Answers1

4

You could try this:

@Test
public void methodDoesNotReturnFor5Seconds() throws Exception {
  Thread t = new Thread(new Runnable() {
    public void run() {
      methodUnderTest();
    }
  });
  t.start();
  t.join(5000);
  assertTrue(t.isAlive());
  // possibly do something to shut down methodUnderTest
}
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614