Wednesday, October 19, 2005

How To Do DB Testing (Part III, Mock Database)

We decided to use Dia to draw the ERD, and to use tedia2sql.pl (available at tigris.org) to pull the data out of the .dia file and generate DDL. In the case of a new table, I'll cut the new DDL out of the generated file and paste it into psql to actually create the table, then run a database diff utility that I wrote (that I already posted to this blog) to make sure what's in the DB is what's in the ERD. (That way, either I or Boss can make quick changes right to the dev DB, and I can make sure they get back to the ERD when things slow down.)

Another good thing about tedia2sql is that, since it's F/OSS, our resident Perl guru could (and did) modify it to spit out text that our internal tool needs, and that another tool (that I wrote) could generate Java classes off of the data model. Kind of like a poor man's Hibernate, perhaps. Once we had working data objects, it was a simple extension to make each of those objects implement a generated interface, and then generate mock objects that don't actually talk to the database, but rather expect to receive one of those Vectors I mentioned earlier.

So now any change to the database automatically updates the real Java objects, and the mock objects that implement the same interface, and a class factory to get a new one as needed. From there, writing Junit tests are the snap you'd expect.

0 Comments:

Post a Comment

<< Home