【问题标题】:How to not stop execution after assertion fails? [duplicate]断言失败后如何不停止执行? [复制]
【发布时间】:2015-05-23 23:44:56
【问题描述】:

我正在使用 Selenium WebDriver + Java + TestNG 进行自动化。在我的测试方法中,有时会有多个断言。

假设有四个断言,第二个断言失败,则终止其余的执行。

我想要的是 - 即使在第二个断言失败之后,应该执行它之后的代码。最后(在执行测试方法之后),它应该返回四个失败的断言,并且测试应该标记为“失败”。

有没有什么方法可以使用Java + TestNG,我可以做到这一点?(我想把这段代码放在某个中心位置,这样我就不必在每个测试方法中添加它)

如果没有断言失败,那么不用担心。它会照常执行。

【问题讨论】:

  • 你检查过这个吗? stackoverflow.com/questions/5402412/…这几乎是你的双重问题。
  • 这听起来好像你的测试做的太多了。你能把有问题的断言分成不同的方法吗?这看起来更干净

标签: java selenium automation automated-tests testng


【解决方案1】:

您可能正在寻找以下内容:

https://rameshbaskar.wordpress.com/2013/09/11/soft-assertions-using-testng/

import org.testng.asserts.Assertion;    
import org.testng.asserts.SoftAssert;        

public class MyTest {

  private Assertion hardAssert = new Assertion();

  private SoftAssert softAssert = new SoftAssert();

  softAssert.assertTrue(false);  

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 2016-12-15
    相关资源
    最近更新 更多