硒中的“断言"与“验证" [英] 'assert' vs. 'verify' in Selenium

查看:72
本文介绍了硒中的“断言"与“验证"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium执行的检查通常有两种形式:assertFoo和verifyFoo.我知道assertFoo会使整个测试用例失败,而verifyFoo只是指出该检查失败并让测试用例继续进行.

The checks Selenium performs usually come in two flavours: assertFoo and verifyFoo. I understand that assertFoo fails the whole testcase whereas verifyFoo just notes the failure of that check and lets the testcase carry on.

因此,通过verifyFoo,即使其中一个条件失败,我也可以获得多个条件的测试结果.另一方面,对于我而言,一项失败的检查足以知道,我的编辑破坏了代码,并且无论如何我都必须对其进行纠正.

So with verifyFoo I can get test results for multiple conditions even if one of them fails. On the other hand, one failing check for me is enough to know, that my edits broke the code and I have to correct them anyway.

在哪种具体情况下,您更喜欢两种检查方式中的一种?您的经历是什么激发了您的观点?

In which concrete situations do you prefer one of the two ways of checking over the other? What are your experiences that motivate your view?

推荐答案

我将使用assert()作为测试的入口点(网关").仅当断言通过时,才会执行verify()检查.例如,如果我要检查由一系列操作产生的窗口的内容,我会先assert()出现该窗口,然后再verify()出现该内容.

I would use an assert() as an entry point (a "gateway") into the test. Only if the assertion passes, will the verify() checks be executed. For instance, if I'm checking the contents of a window resulting from a series of actions, I would assert() the presence of the window, and then verify() the contents.

我经常使用的一个示例-检查jqgrid中的估算值:assert()网格的存在,以及verify()估算值.

An example I use often - checking the estimates in a jqgrid: assert() the presence of the grid, and verify() the estimates.

这篇关于硒中的“断言"与“验证"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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