title: How does Mockito timeout work?
body: <p>I'm new to Mockito and JUnit and try to understand basic unit testing with these frameworks. Most concepts in JUnit and Mockito seem straightforward and understandable. However, I got stuck with <code>timeout</code> in Mockito. Does <code>timeout</code> in Mockito play the same role as it does in JUnit? Bellow is my code. </p>
  
  <pre><code>@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></pre>
  
  <p>I expected that both tests failed. But only <code>testJUnitTimeout()</code> failed. Why does the second test pass?</p>
  
  <p>Thank you very much.</p>