glen.blog-city.com - Ant, JUnit and SQL seems to be doing the same thing I am lately : setting up the build process, using ANT, doing Db setup for them etc...
Here is how I did it : our project is built using ANT. I have a target that creates the whole EAR (we're using EJB). I have a target that compiles the testsuite and another that starts weblogic, deploys the EAR, runs the tests and stops the server.
Every tests derives from DatabaseTestCase which extends TestCase. This class uses DbUnit (http://dbunit.sf.net) which is great tool...
This class has two methods of interest : emptyAllTables() which empties all the tables from the database and insertFileIntoDb() . This method takes the name of an XML file that is on the test's classpath. This is a flat xml file of what the contents of the database should be. We have one such file for each table. Whenever we test a method in a class, we load the necessary tables. We created these files by extracting the contents of a test DB using DbUnit itself
This allows us to prevent side effects and to control the test environment when mocking objects is not a possibility.
A few great things about DbUnit : it can handle blobs, it can handle DBs with multiple schemas such as Orcale, it has lots of other nice features such as SQL queries through a simple interface, etc...
Thanks for posting this. DBUnit does a lot of things we are currently trying to do and I am interested to get more into their code.
Posted by: Michael Wall at March 7, 2003 05:46 PMdbUnit was on my tools to investigate list for several months. I'm preparing for a big refactoring task and I want be sure that heavily changing the business logic layer won't break neither user interface nor persistence.
Your post confirms that I should look at dbUnit ASAP for database stuff. User interface part can be covered by Acceptance Testing and FitNesse http://fitnesse.org seems a very promising candidate for it.
Posted by: Edmundas at March 9, 2003 04:20 PM