区分 0 和 db 中的一些数据集(均为有效情况)
目前我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该有两个测试,每个测试都期望不同的结果:一个期望 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.