如果特定测试失败,则停止JUnit套件
问题描述:
我有以下形式的JUnit测试套件:
I have a JUnit test suite in the form:
@RunWith(Suite.class)
@Suite.SuiteClasses( { xx.class, yy.cass })
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
//$JUnit-BEGIN$
//$JUnit-END$
return suite;
}
}
然后调用这样的vanilla测试:
This then calls vanilla tests like this:
public class xxx {
@Test
public void test () throws {
...
我有一种情况,我想停止运行测试套件的其余部分如果在第一次测试中出现错误或失败。但是其他错误/失败是可以的,套件应尽可能多地完成其他测试。基本上,第一次测试失败将表明运行其余测试是不安全的。
I have a situation where I'd like to stop the rest of the test suite running if there's an error or fail in the first test. But errors / fails in the others are ok and the suite should complete as many other tests as it can. Basically the first test failing would indicate it isn't safe to run the rest.
这可能吗?
答
调用 System.exit()?