问题
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