Adam A. wrote:
How does one go around creating unit tests for database tables during
developement. Is there a rock solid work flow plan that everyone uses.
A myth of software development is you can plan out and invent your
schema before writing your code. This myth is so pervasive that some
(>cough< Oracle) actively prevent programmers from changing their
Refactoring databases is a Best Practice, and all projects should
support scripts that overcome our database platform limitations.
Im new to dbs and relatively so with unit tests. I have my project and
it usually starts with a rough idea of what fields need to be in the
table. As i code away items in the db change so it makes it difficult to
write unit tests that will withstand these changes.
Investigate (and use!) the ActiveRecord system exemplified in Rails
migrations. When your program starts, only only only put in the
very few fields you are actually using. Rails’s “script/generate model”
write a migration which adds that table to the db. Write tests for the
behavior, and these will require fields in the table. Edit the model’s
file to add them. Repeat in tiny cycles, testing and integrating as
possible. Never integrate if the tests break - revert if necessary.
more efficient than debugging!)
I know i need a test version of a database with static items but what id
like to do is for this test version to always reflect whats happening in
the development one. So if I add a field in the development one, the
test one gets one too.
Put sample data into the fixture files, and use it in the tests. Your
should then be able to migrate your test, development, and production
If you are not writing a Rails project, research how to get all these
without its framework. Rails can import fixture data into the
database with ‘rake db:migrate’.
When you deploy to a live site, at this point stop editing your initial
migration files, and only add new files that add and adjust your fields.
I could just go and code this and probably get something that works but
is probably ugly. I dont like to reinvent the wheel, a bad one at that
so if anyone has some tips or pointers in the right direction id really
This is for small projects so it doesnt have to industrial strength
bullet proof ninja stuff, small but elegant will be good enough
These techniques - after you spend a little time implementing them -
potentially big projects very small and manageable. I would use them on
of any size!