“时间测试”是指,一个单元测试运行时间是否超过指定的毫秒数,测试将终止并标记为失败。

import org.junit.*;

/**
 * JUnit TimeOut Test
 * @author yiibai
 *
 */
public class JunitTest4 {

	@Test(timeout = 1000)  
	public void infinity() {  
		while (true);  
	}  
    
}

在上面的例子中,infinity() 方法将不会返回,因此JUnit引擎将其标记为失败,并抛出一个异常。

java.lang.Exception:test timed out after 1000 milliseconds

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-28
  • 2021-05-30
  • 2021-09-08
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案