我正在尝试在 TestNG 中编写一个测试方法,在它失败后 - 整个测试套件将停止运行。
@Test
public void stopTestingIfThisFailed() throws Exception
{
someTestStesp();
if (softAsserter.isOneFailed()) {
asserter.fail("stopTestingIfThisFailed test Failed");
throw new Exception("Test can't continue, fail here!");
}
}
正在抛出异常,但正在运行其他测试方法。
如何解决?
最佳答案
您可以在其他测试方法中使用 dependsOnMethods
或 dependsOnGroups
注释参数:
@Test(dependsOnMethods = {"stopTestingIfThisFailed"})
public void testAnotherTestMehtod() {
}
JavaDoc of the dependsOnMethods
parameter :
The list of methods this method depends on. There is no guarantee on the order on which the methods depended upon will be run, but you are guaranteed that all these methods will be run before the test method that contains this annotation is run. Furthermore, if any of these methods was not a SUCCESS, this test method will not be run and will be flagged as a SKIP. If some of these methods have been overloaded, all the overloaded versions will be run.
参见 https://testng.org/doc/documentation-main.html#dependent-methods
关于java - 如何在测试失败后停止运行 TestNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56220735/