[英]How to accept Junit 5 test after timeout?
当我将@timeout
放在测试上方时,它会在运行时间过长时失败。
热到将其标记为已通过?
根据@timeout 的文档,如果方法没有满足在规定时间内完成其操作,则@timeout 测试失败。 因此,如果方法花费的时间比预期的要长,则不能使用 @timeout 将其标记为已通过。
否则,基于另一个问题,为了达到您的目的,您可以使用 Java Thread 和 sleep() 方法在一段时间后检查 Thread.isAlive() 是否。 例子:
...
// Create and start the task thread.
Thread taskThread = new Thread(){
public void run(){
System.out.println("Thread Running");
}
}
taskThread.start( );
// Wait 3 seconds.
sleep(3000);
boolean status = false;
// If after waiting 3 seconds the task is still running, stop it.
if (taskThread.isAlive( )) {
taskThread.interrupt( );
} else {
status = true;
}
assertTrue(status);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.