Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在断言失败后不停止执行?_Java_Selenium_Automation_Automated Tests_Testng - Fatal编程技术网

Java 如何在断言失败后不停止执行?

Java 如何在断言失败后不停止执行?,java,selenium,automation,automated-tests,testng,Java,Selenium,Automation,Automated Tests,Testng,我使用SeleniumWebDriver+Java+TestNG实现自动化。在我的测试方法中,有时有不止一个断言 假设有四个断言,第二个断言失败,则剩余的执行被终止 我想要的是——即使在第二次断言失败之后,也应该执行它之后的代码。最后(在执行测试方法之后),它应该返回四个断言中失败的断言,并且测试应该标记为“失败” 有没有办法使用Java+TestNG,我可以做到这一点?(我想把这段代码放在某个中心位置,这样我就不必在每个测试方法中都添加它) 如果没有任何断言失败,那么就不必担心。它将像往常一样

我使用SeleniumWebDriver+Java+TestNG实现自动化。在我的测试方法中,有时有不止一个断言

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

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

有没有办法使用Java+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);  

}