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

本文是小编为大家收集整理的关于如何测试网页代码?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

是否有人有一些很好的提示,用于编写数据库 - 倒实开发的测试代码,在此对状态有很大的依赖?

具体来说,我想为从数据库中检索记录的代码编写测试,但是答案将取决于数据库中的数据(可能会随时间变化).

人们通常使用"冷冻"数据库制作单独的开发系统,以便任何给定的功能始终返回完全相同的结果集?

我很确定这不是一个新问题,所以我很想从他人的经验中学习.

是否有很好的文章讨论这个基于Web的开发问题?

我通常会编写PHP代码,但我希望所有这些问题都在很大程度上是语言和框架.

推荐答案

您应该研究dbunit,或尝试找到一个php等效物(那里必须有一个).您可以使用它来准备使用代表您的测试数据的特定数据集的数据库,因此每个测试将不再取决于数据库和某些现有状态.这样,每个测试都是自我包含的,并且不会在进一步的数据库使用过程中破裂.

更新:快速的Google搜索显示> DB单位扩展用于Phpunit.

其他推荐答案

如果您主要关注数据层测试,则可能需要查看这本书: Xunit测试模式:重构测试代码.我本人总是不确定,但是这本书做得很好,可以帮助列举诸如表现,可重复性等的担忧.

.

其他推荐答案

我想这取决于您正在使用的数据库,但是红色门(www.red-gate.com)使一个称为SQL数据生成器的工具.可以将其配置为以填充您的数据库,并使用明智的测试数据.您还可以告诉它始终在其随机数生成器中使用相同的种子,因此每次"随机"数据都是相同的.

您可以编写单元测试以利用此可靠,可重复的数据.

为了测试网络端,我目前正在研究硒(selenium.openqa.org).这似乎是一个跨浏览器的测试套件,可以帮助您测试功能.但是,与所有这些网站测试工具一样,没有真正的方法可以测试这些东西在所有浏览器中的外观,而不会对其进行人类眼光!

本文地址:https://www.itbaoku.cn/post/597667.html

问题描述

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?

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

推荐答案

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.

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

其他推荐答案

If you're mostly concerned with data layer testing, you might want to check out this book: xUnit Test Patterns: Refactoring Test Code. I was always unsure about it myself, but this book does a great job to help enumerate the concerns like performance, reproducibility, etc.

其他推荐答案

I guess it depends what database you're using, but Red Gate (www.red-gate.com) make a tool called SQL Data Generator. This can be configured to fill your database with sensible looking test data. You can also tell it to always use the same seed in its random number generator so your 'random' data is the same every time.

You can then write your unit tests to make use of this reliable, repeatable data.

As for testing the web side of things, I'm currently looking into Selenium (selenium.openqa.org). This appears to be a cross-browser capable test suite which will help you test functionality. However, as with all of these web site test tools, there's no real way to test how well these things look in all of the browsers without casting a human eye over them!