如何测试Web代码? [英] How to Test Web Code?

查看:107
本文介绍了如何测试Web代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人为编写用于数据库 - 后端开发的测试代码提供了一些好的提示,其中存在对状态的严重依赖?

Does anyone have some good hints for writing test code for database-backend development where there is a heavy dependency on state?

具体来说,代码,从数据库中检索记录,但答案将取决于数据库中的数据(可能随时间而变化)。

Specifically, I want to write tests for code that retrieve records from the database, but the answers will depend on the data in the database (which may change over time).

人们通常做一个单独的开发系统一个'冻结'数据库,以便任何给定的函数应该总是返回完全相同的结果集?

Do people usually make a separate development system with a 'frozen' database so that any given function should always return the exact same result set?

我相信这不是一个新的问题,所以我会非常感兴趣从其他人的经验中学习。

I am quite sure this is not a new issue, so I would be very interested to learn from other people's experience.

有没有很好的文章讨论这个基于网络的开发问题?

Are there good articles out there that discuss this issue of web-based development in general?

我通常编写PHP代码,但我希望所有这些问题主要是语言和框架无关的。

I usually write PHP code, but I would expect all of these issues are largely language and framework agnostic.

推荐答案

您应该查看DBUnit,或尝试找到一个PHP等价物(必须有一个)。您可以使用它来准备数据库,其中包含表示测试数据的特定数据集,因此每个测试将不再依赖于数据库和某些现有状态。这样,每个测试都是自包含的,并且在进一步的数据库使用期间不会中断。

You should look into DBUnit, or try to find a PHP equivalent (there must be one out there). You can use it to prepare the database with a specific set of data which represents your test data, and thus each test will no longer depend on the database and some existing state. This way, each test is self contained and will not break during further database usage.

更新:快速的google搜索显示数据库单元扩展

Update: A quick google search showed a DB unit extension for PHPUnit.

这篇关于如何测试Web代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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