即使在测试超时并失败后,似乎runClasses()
也不会终止正在测试的代码。
SSCCE:
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
class Main {
public static void main(String[] args) {
Class<?>[] classes = { PublicTest.class };
Result result = JUnitCore.runClasses(classes);
System.out.println("Num tests: " + result.getRunCount());
System.out.println("Time: " + result.getRunTime());
System.out.println("Failure: " + result.getFailures().get(0));
}
}
测试类:
import org.junit.Test;
public class PublicTest {
@Test(timeout=10)
public void loop() {
while(true) {}
}
}
如何让代码终止?