Bryan Pendleton on 05/04/08 17:13, wrote:
I have a simple requirement in my unit test run to run integration
tests on my java application's persistence layer.
Each test must (1) create the schema, (2) insert the fresh test data,
(3) run the test and (4) clean up and remove the database.
Have a look at CleanDatabaseTestSetup.java in the Derby source tree.
Derby's built-in JUnit tests do almost the same thing as you describe,
so it is a very common pattern in that code.
Browse around there and you should find some good examples of coding
patterns for these tasks.
Yes, great use for the decorator pattern, although it's quite laborious
following the code in HTML - guess I should have downloaded it :O
I didn't think that deleting the foreign keys was necessary, but that extra loop
to go over the foreign keys and drop them all first fixed the issue.
So thanks alot for the pointer.
Just a slight niggle though that I have, and that is on the lack of warning at
the end of the 'drop table' loop beforehand - I should have received some sort
of error that my tables did not in fact drop quietly, when in fact I received none.
Regards
Adam