Ben
Ben

Reputation: 127

JUnit: Test should pass if it hangs for a certain amount of time

I found code that will cause a test to fail if it runs for longer than timeout ms. What if I want it to pass? I have a function that I expect will hang forever. If it hangs for long enough, say 10000 ms, then I assume that it's hanging forever and the test should pass.

@Test(timeout=10000) public void test() {
   while(true)
}

Upvotes: 2

Views: 661

Answers (1)

staszek
staszek

Reputation: 251

You said you want to test that querying a closed connection will hang forever. (The code retries establishing the connection forever) So you want to hang your program forever, everytime someone tries to query closed connection?

I would better throw exception when connection is closed.

Upvotes: 2

Related Questions