单元测试数据库
我想将我的数据库作为一组集成测试的一部分进行测试。我已经对所有代码单元进行了针对模拟等的速度测试,但我需要确保所有存储过程和代码在持久化时都能正常工作。我昨天用谷歌搜索了一下,在这里发现了一篇不错的文章 http://msdn.microsoft。 com/en-us/magazine/cc163772.aspx,但看起来有点旧。我想知道当前是否有任何“更好”的方法来清除数据库、恢复到预期状态或回滚为每个测试做好准备?我正在使用 sql 2008 在 c#4、mvc3 中进行编码。
I want to test my database as part of a set of integration tests. I've got all my code unit tested against mocks etc for speed but I need to make sure all the stored procedures and code is working as it should when persisting. I did some Googling yesterday and found a nice article here http://msdn.microsoft.com/en-us/magazine/cc163772.aspx but it seemed a little old. I wondered if there is any current 'better' way of clearing out the database, restoring to an expected state or rolling back ready for each test? I'm coding in c#4, mvc3 using sql 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们使用 DbUnit 在测试之间设置和/或拆除数据库,并在测试期间断言数据库状态测试。
We are using DbUnit to set up and/or tear down the database between tests as well as to assert database state during test.
这很愚蠢-简单,所以它可能不完全是您所需要的,但我所做的是将数据库的备份保留在给定的正常状态 - 通常是当前的生产数据库。然后,对于每个构建,我们恢复该数据库(使用 Jenkins、NANT 和 SQLCMD),应用当前构建更新脚本并运行我们的测试套件。这样做的优点是既可以为您提供一个“已知数量”的数据库,又可以验证您的升级脚本是否正常工作。
It's stupid-simple, so it may not be exactly what you need, but what I've done is keep a backup of the database at a given sane state - usually what the current production database is it. Then, for each build we restore that database (using Jenkins, NANT and SQLCMD), apply the current builds update scripts and run our test suite. This has the advantage of both giving you a database that is a 'known quantity' and it verifies that your upgrade scripting is working.