如何断言失败后不停止执行? [英] How to not stop execution after assertion fails?

查看:1383
本文介绍了如何断言失败后不停止执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用webdriver的硒+ Java的+ TestNG的自动化。在我的测试方法,有时也有不止一个断言。

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.

我要的是 - 第二断言失败,code即使经过后,就应该执行。并在年底(执行测试方法后),它应该返回什么断言失败了四个和测试应该被标记为失败。

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".

有没有使用Java + TestNG的任何方式,我可以做到这一点?(我想将这个code。在一些集中的地方,所以我不会把它添加在每个测试方法)

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.

推荐答案

下面的东西,你可以寻找:

Here's something that you could be looking for:

的https://rameshbaskar.word press.com / 2013/09/11 /软断言,使用-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);  

}

这篇关于如何断言失败后不停止执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆