如何通过Junit获得成功并暂停?
@Test (expected=TimeoutException.class,timeout=1000) public void fineForFiveSeconds() { foo.doforever(); fail("This line should never reached"); }
这是我的测试代码。 我想要的是运行doforever()
一段时间然后让测试成功。
尝试这个:
执行线程中的逻辑,睡眠并检查线程是否仍然存活。
@Test public void fineForFiveSeconds() throws InterruptedException { Thread thread = new Thread() { @Override public void run() { foo.doforever(); } }; thread.start(); //Let the current thread sleep (not the created thread!) Thread.sleep(5000); assertTrue(thread.isAlive()); }