I have a JUnit test case where I'm expecting a particular method call to take a long time (over a minute). I want to
How do I do this?
You can write a class implementing runnable that wraps around the method of interest; assuming spawning threads is allowed.
public class CallMethod implements Runnable
{
//time in milli
public long getStartTime()
{
return startTime;
}
//time in milli
public long getEndTime()
{
return endTime;
}
public void run()
{
startTime = ...;
obj.longRunningMethod();
endTime = ...;
}
}
Then in your JUnit you can do something like:
public void testCase1()
{
CallMethod call = new CallMethod();
Thread t = new Thread(call);
t.start();
t.join(60000); // wait one minute
assertTrue(t.alive() || call.getEndTime() - call.getStartTime() >= 60000);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With