如何自动化功能/集成测试和数据库回滚 [英] How to automate functional/integration tests and database rollbacks

查看:1518
本文介绍了如何自动化功能/集成测试和数据库回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相反我<一href=\"http://stackoverflow.com/questions/1458524/integration-testing-using-selenium-and-nunit-from-ui-to-db\">$p$pvious问题,我会尽量给我的要求。

In contrast to my previous question, i'll try to give my requirements.

我试图找到一些框架/方法/东西,将适合以下内容:

I am trying to find some framework/methodology/"thing" that would fit the following:


  • 有能力编写自动测试,preferably写在Visual Studio中,使用C#。

  • 测试应该推动一个网页浏览器,并与SUT就像一个用户交互会。

  • 测试应该能够设置一个测试场景中DB。

  • 测试应该可以断言,用户交互曾在DB预期的效果。

  • 测试完成后,它应该能够回滚它DB的所有更改。

我的第一次尝试是使用NUnit测试驱动硒(在这之前华廷),但我遇到了一点问题(检查上面的链接),而使用的TransactionScope回滚的变化硒驱动器中没有DB。

My first attempt was to use NUnit test to drive Selenium (and Watin before that), but i faced a bit of a problem (check the link above) while using TransactionScope to roll back the changes Selenium-driven browser did in the DB.

有没有人做过这样的事,在现实世界?我发现通过谷歌提供一些参考,但一直没能找到关于如何落实这一任何具体的例子。不会有任何问题,如果我会做单元测试。在这种情况下的TransactionScope将是相当不够的。

Has anyone done anything like this in the "real world"? I've found some references through Google, but haven't been able to find any concrete examples on how to implement this. There wouldn't be any problems if i'd be doing unit testing. In that case TransactionScope would be quite enough.

编辑: R.哈维向我指出<一个href=\"http://stackoverflow.com/questions/768944/rollback-database-after-integration-selenium-tests\">this问题,这几乎等同于我的情况。

R. Harvey pointed me to this question, which is almost identical to my situation.

不过这个问题仅仅是几乎的相同。我的应用程序是一个家庭服务的一部分,所有的人都访问同一套数据库表。要求不允许有效利用滴/创建的脚本测试数据量,所以有一些这方面的替代的解决方案?

However that question is just almost identical. My application is part of a family of services, all of them accessing the same set of database tables. Amount of test data required does not allow for efficient use of drop/create-scripts, so is there some alternate solution for this?

我们使用SQL Server 2005,我不在数据库中的魔法很精通,所以如果有一些方法使用比降其他SQL脚本/创建,那么这可能是一个选项。

We are using SQL Server 2005, and i'm not very proficient in database magic, so if there's some way to use sql scripting other than drop/create, then that could be an option.

编辑2:

根据的答案和一些额外的挠头,我们会去更轻量级的数据库开发人员执行单位 - ,集成 - 测试和功能测试。这使我们能够使用SQL的脚本建立和拆除的考验。

Based on the answers and some additional head scratching, we'll go for more lightweight databases for developers to perform unit-, integration- and functional testing. This enables us to use sql-scripts for setting up and tearing down the test.

推荐答案

在一个事务中所做的更改才可见里面说的交易。还包裹在一个事务范围(如果可能)的测试将让测试行为不同于真实的东西在一个非常关键的环节(交易)。

Changes made in a transaction are only visible inside said transaction. Also wrapping the test in a transaction scope (if possible) would make the test behave differently than the real thing in a very critical aspect (transactions).

有更好的使用你的每个测试套件之前恢复数据库的形象。该套件完成和验证完成后这样一来,你把测试数据库。接下来的运行,该套件安装过程中,该数据库是从保存的图像中原始状态重新创建准备测试。更妙的是有从头开始部署数据库的脚本和套件安装过程中运行该脚本。

It is much better to use a database image that you restore before every test suite. This way after the suite completes and the verification is done, you drop the test database. The next run, during the suite setup, the database is re-created from the saved image in a pristine state ready for testing. Even better would be to have a script that deploys the database from scratch and run that script during suite setup.

顺便说一句是不可行的每次测试之前恢复到原始状态。更一般地是不具有冗长个别测试设置和清除步骤是可行的。当您添加更多的测试所花的时间恢复数据库测试就绪状态的测试会变得不可收拾刚。与上百次试验套房试验数万相当普遍和充分的测试运行将意味着小时,仅仅花了恢复数据库的测试时间。设计您的测试,使他们可以独立运行,即得。试验N有能力生产,即使试验N-1没有有效的结果。

Btw is not feasible to restore to a pristine state before every test. More generically is not feasible to have lengthy individual test setup and cleanup steps. As you add more tests the time spent restoring the database to test-ready condition between tests will become just unmanageable. Suites with hundreds of tests are quite common and full test runs of tens of thousands of tests would mean hours and hours spent just restoring database for test. Design your individual test so that they can be run independently, ie. test N has to produce valid results even if test N-1 failed.

另一个要考虑的是故障调查,你希望你的测试失败离开的状态的数据库,可以为有意义的信息的的你想随后的测试需要能够运行并产生有效的被调查结果。有时,这些要求会相互矛盾,但必须加以考虑和设计你的测试。

Another thing to consider is failure investigation, you want your failed test to leave the database in a state that can be investigated for meaningful info and you want subsequent tests to be able to run and produce valid results. Sometimes these requirements will contradict each other, but you must take them into consideration and design your test around them.

这篇关于如何自动化功能/集成测试和数据库回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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