'断言'与“验证”相比硒

发布于 2024-11-02 20:14:52 字数 256 浏览 1 评论 0原文

Selenium 执行的检查通常有两种形式:assertFoo 和 verifyFoo。据我所知,assertFoo 使整个测试用例失败,而 verifyFoo 只是记录该检查的失败并让测试用例继续进行。

因此,使用 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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赤濁 2024-11-09 20:14:52

我将使用 assert() 作为测试的入口点(“网关”)。仅当断言通过时,才会执行 verify() 检查。例如,如果我要检查由一系列操作产生的窗口的内容,我会 assert() 窗口是否存在,然后 verify()内容。

我经常使用的一个例子 - 检查 jqgrid 中的估计: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.

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

烟雨凡馨 2024-11-09 20:14:52

我遇到了一些问题,这些问题可以通过使用来克服

assert*()

verify*()

例如,在表单验证中,如果您想检查表单元素,可以使用

verifyTrue(...);

will just pass the test even if the string is not present in the form.

如果将断言替换为验证,那么它会按预期工作。

我强烈建议使用 assert*()

I've come across a few problems which were overcome by using

assert*()

instead of

verify*()

For example, in form validations if you want to check a form element, the use of

verifyTrue(...);

will just pass the test even if the string is not present in the form.

If you replace assert with verify, then it works as expected.

I strongly recommend to go with using assert*().

江南烟雨〆相思醉 2024-11-09 20:14:52

如果您在生产系统上运行 Selenium 测试并希望确保您以测试用户身份登录(例如,而不是您的个人帐户),那么最好在触发任何操作之前首先断言正确的用户已登录。如果不小心使用,可能会产生意想不到的效果。

If you are running Selenium tests on a production system and want to make sure you are logged-in as a test user e.g., instead of your personal account, it is a good idea to first assert that the right user is logged in before triggering any actions that would have unintended effects, if used by accident.

不羁少年 2024-11-09 20:14:52

通常,您应该坚持每个测试用例一个断言,在这种情况下,差异归结为必须运行的任何拆卸代码。但无论如何,您应该将其放入 @After 方法中。

我在 SeleneseTestBase 中的 verify*() 方法上遇到了很多问题(例如,它们使用 System.out.println()com.thoughtworks .selenium.SeleneseTestBase.assertEquals(Object, Object) 只是没有达到您的预期),所以我已经停止使用它们。

Usually you should stick to one assertion per test case, and in this case the difference boils down to any tear-down code which must be run. But you should probably put this in an @After method anyway.

I've had quite a few problems with the verify*() methods in SeleneseTestBase (e.g. they use System.out.println(), and com.thoughtworks.selenium.SeleneseTestBase.assertEquals(Object, Object) just doesn't do what you expect) so I've stopped using them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文