java - 如何在测试失败后停止运行 TestNG

标签 java selenium testng

我正在尝试在 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!");
    }
}

正在抛出异常,但正在运行其他测试方法。

如何解决?

最佳答案

您可以在其他测试方法中使用 dependsOnMethodsdependsOnGroups 注释参数:

@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/

相关文章:

java - 测试 NG : turning a @BeforeClass into something else (@BeforeSuite maybe? )

java - 错误- TestngTestSuiteUsingXML.java :6: error: package org. testng 不存在

java - 在 TestNG 中使用 @BeforeMethod 时有没有办法获取方法元数据?

java - Swing 中的彩色 xml 显示

Python Selenium Webdriver - 即时更改代理设置

c# - Selenium - 强制点击不可见元素

java - Selenium /Java : can I separate a Drag and Drop action in two actions belonging to two separate classes?

javafx gridpane 居中对齐并对齐所有标签

java - 扫描仪一开始就忽略空白

java - List 类型不是通用的;它不能用参数参数化