我应该编写哪些数据库测试,以便轻松地重构数据库

[英]What database tests should I write so that refactoring database is easy


Are there any guidelines on writing database tests so that you can refactor database "without fear" while doing evolutionary database design?

是否有关于编写数据库测试的指导原则,以便您在进行进化数据库设计时可以“无所畏惧”地重构数据库?

What aspects of database should be put to test while developing it? Any example would be great..

数据库的哪些方面应该在开发时进行测试?任何一个例子都会很棒..

4 个解决方案

#1


I write tests that call my dal code and after I check if the inserts/updates/deletes actually occurred, so called state tests. These are pr definition not Units test but rather integration tests, but they have actually helped me many times doing database changes. Over the time I have more and better tests and even bigger database changes go rather seamlessly.

我编写调用我的dal代码的测试,然后检查插入/更新/删除是否实际发生,所谓的状态测试。这些是pr定义而不是单元测试,而是集成测试,但它们实际上帮助我多次进行数据库更改。随着时间的推移,我有更多更好的测试,甚至更大的数据库更改也相当无缝。

#2


The concept of having tests, according to TDD, is that you test the way things are meant to work now. When you need to change something, you change the tests that address that, (ensure the current codebase fails), and then make the code changes until the tests pass. The tests that didn't change give you confidence that other aspects of your software is still doing what it used to and that your refactoring hasn't broken anything.

根据TDD,测试的概念是你测试现在的工作方式。当您需要更改某些内容时,可以更改解决该问题的测试(确保当前代码库失败),然后更改代码,直到测试通过。没有改变的测试让你相信你的软件的其他方面仍然在做它曾经做过的事情,并且你的重构没有破坏任何东西。

So you don't write tests with refactoring in mind; rather, you test your requirements, and then when your requirements change you update the tests accordingly, and refactor the code so it passes the new tests.

所以你不要在考虑重构的情况下编写测试;相反,你测试你的需求,然后当你的需求改变时,你相应地更新测试,并重构代码,以便它通过新的测试。

#3


Always fear every change you make to a database. This will compel you to double check every thing you change and narrow down the possible errors.

始终担心您对数据库所做的每一项更改。这将迫使您仔细检查您更改的每件事情并缩小可能的错误范围。

Keep in mind that databases are usually the backbone of one or more application, so every change you make must be planned carefully and properly tested.

请记住,数据库通常是一个或多个应用程序的主干,因此您所做的每项更改都必须仔细规划并进行适当测试。

#4


When writing stored procedures, I liberally add Debug / Print statements. With @Debug as a input parameter of type bit :

在编写存储过程时,我自由地添加了Debug / Print语句。使用@Debug作为bit类型的输入参数:

IF @Debug = 1 PRINT @MyDynamicVariable
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2009/01/14/13cf698693dbc203eff66c3515de204e.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告