测试驱动开发 - 我应该测试数据库列和索引吗? [英] Test Driven Development - Should I test database columns and indexes?

查看:31
本文介绍了测试驱动开发 - 我应该测试数据库列和索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 TDD 的新手.我发现 should gem 能够测试数据库实体的列是否存在,以及测试其索引的能力.

I am new to TDD. I find that the shoulda gem has the ability to test if a column exists for a database entity as well as the ability to test its indexes.

我是否需要担心在开发过程中可能删除任何列和索引?

Will I need to be concerned with a potential deletion of any of the columns and indexes during development?

推荐答案

不要测试数据库列;那只是测试实现.不要测试实现,测试行为.测试使用存储在这些列中的属性的功能.例外:如果您的架构有外部要求(这在我身上从未发生过,但我可以想象),编写测试以证明这些要求得到满足可能会有所帮助.

Don't test database columns; that's just testing implementation. Don't test implementation, test behavior. Do test functionality that uses the attributes that are stored in those columns. Exception: if there are external requirements on your schema (this has never happened to me but I can imagine it), it might be helpful to write tests to show that those requirements are met.

测试索引?这取决于.如果您是严格测试驱动的,您可能希望为纯粹出于性能原因添加的每个索引编写一个测试.我很受测试驱动,但我不写这样的测试;我只是创建索引.对指标的真正考验是它们对性能的影响.在任何情况下,测试都必须存在索引以支持您已经测试的功能(主键、外键、唯一约束等)是没有意义的.

Test indexes? It depends. If you're strictly test-driven, you may want to write a test for each index that you add purely for performance reasons. I'm pretty test-driven, but I don't write tests like this; I just create the indexes. The real test of the indexes is their effect on performance. In any case, there is no point in testing that indexes exist that have to exist anyway to support functionality that you're already testing (primary keys, foreign keys, unique constraints, etc.).

这篇关于测试驱动开发 - 我应该测试数据库列和索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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