Test Driven Development. Should I test database columns and indexes?

I am new to TDD. I found that the stone shoulda has the ability to check if a column exists for a database object, as well as the ability to check its indexes.

But do I need to enable column and index testing in my test case?

Should I be interested in potentially deleting any of the columns and indexes during development?

+3
source share
2 answers

Do not test database columns ; it's just testing the implementation. Do not check the execution, the behavior of the test. Use a test function that uses the attributes that are stored in these columns. Exception: if your circuit has external requirements (this has never happened to me, but I can imagine it), it would be useful to write tests to show that these requirements are met.

Test indices? It depends. If you are strictly controlled by testing, you can write a test for each index that you add solely for performance reasons. I am quite experienced, but I do not write such tests; I just create indexes. The real test of indices is their impact on performance. In any case, it makes no sense to test existing indexes, which must exist in any case to support functions that are already being tested (primary keys, foreign keys, unique constraints, etc.).

+3
source

I rarely test columns and indexes. If you want your migrations or database restrictions to be correct, you can enable them. Production will become a logical copy of development. Therefore, if you really care about all the potential risks, you can write a test case.

0
source

Source: https://habr.com/ru/post/1247629/


All Articles