区分 0 和 db 中的一些数据集(均为有效情况)

发布于 2024-09-18 16:30:02 字数 204 浏览 1 评论 0原文

目前我正在使用 phpunit 为一些访问 mysql 数据库的函数编写测试。现在我不确定如何区分函数何时返回一些数据集或什么都不返回(两者都是有效的函数结果)。我应该使用不同的测试(这样其中一个在任何情况下都会失败)还是在这种情况下可以使用可能跳过断言的 if ?如果有的话,我必须对结果进行一些测试。

我知道之前已经有人问过这个问题,但我无法制定适当的查询来得到答案,抱歉。

currently I'm using phpunit to write tests for some functions that access a mysql-database. Now I'm unsure what to do to distinguish when a function returns some datasets or nothing (which both are valid function results). Should I use different tests (so that one of them will fail in any case) or is it in this case ok to use an if that possibly skips asserts? I have to do some tests on the results, if there are some.

I know this has been asked before somewhere already, but I couldn't formulate a proper query to get me an answer, sorry.

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

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

发布评论

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

评论(1

北凤男飞 2024-09-25 16:30:02

您应该有两个测试,每个测试都期望不同的结果:一个期望 0 (它表示错误或只是没有结果),另一个 - 数据集(顺便说一句,数据集可以为空?并且,在错误时,您有空数据集或只是 null/false /0 无论如何?)

您可以使用不同的查询或不同的装置集来确保不同的响应。您还可以完全模拟响应或使用不同的数据库。这完全取决于您的测试和应用程序的结构。

You should have two tests, each one expecting different result: one expecting 0 (it indicates error or just no result), another one - dataset (can be dataset empty btw? and, on error, you have empty dataset or just null/false/0 whatever?)

you can use different queries or different fixtures sets to ensure different responses. You can also completly mock the response or use different dbs. It all depends of structure of your tests and app.

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