问题
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.
But is it necessary to include testing of columns and indexes in my test suite?
Will I need to be concerned with a potential deletion of any of the columns and indexes during development?
回答1:
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.).
回答2:
I rarely test of columns and indexes. If you want to make sure your database migrations or constraint correct, you might include it. Production will be a logical copy of development. So if you really care about all potential risks, you might write the test case.
来源:https://stackoverflow.com/questions/36725509/test-driven-development-should-i-test-database-columns-and-indexes