How to not stop execution after assertion fails? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-16 00:36:18

问题


I'm using Selenium WebDriver + Java + TestNG for automation. In my test methods, sometimes there are more than one assertions.

Suppose, there are four assertions and second assertion fails, then rest of the execution is terminated.

What I want is - even after second assertion fails, code after it should be executed. And at the end(after test method is executed), it should return what assertions are failed out of four and test should be marked as "Fail".

Is there any way using Java + TestNG, I can achieve this?(And I would like to put this code at some central place, so that I won't have to add it in every test method)

If no assertion fails, then no worries. It'll execute as usual.


回答1:


Here's something that you could be looking for:

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);  

}


来源:https://stackoverflow.com/questions/29168684/how-to-not-stop-execution-after-assertion-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!