Код: Выделить всё
@Mock Timeoutable timeoutable;
@Test(timeout = 100)
public void testJUnitTimeout() {
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
}
@Test
public void testMockitoTimeout(){
doAnswer(new Answer() {
@Override public Object answer(InvocationOnMock invocation){
try {
Thread.sleep(1000);
} catch (InterruptedException ie){
}
return null;
}
}).when(timeoutable).longOperation();
timeoutable.longOperation();
verify(timeoutable, timeout(100)).longOperation();
}
< /code>
Я ожидал, что оба теста не удались. Но только testjunittimeout () Большое спасибо. < /P>
Подробнее здесь: https://stackoverflow.com/questions/313 ... meout-work