I would like to leverage the existing database as a source for JUnit test data. Some scenarios are quite complex and it is a hassle to set up all the objects manually.
I am thinking in terms of a decorator for my existing DAO that will serialize the objects my real SQL connected DAO is returning from the database and record them to files.
Something along the lines of running the JUnit testcase in record once mode and afterwards always replaying the recorded data and not going to the database.
Are there frameworks for Java to ease this process or do I have to implement it myself?
You can set up a logging JDBC proxy (like JdbcProxy, log4jdbc, jdbcdslog or DbdaTestDriver) between your application and the database to save the queries and result sets returned. You won’t have to write and inject any DAO decorators.
Later on you can use the logged data to set up a stub database connection for use in tests. JdbcProxy and DbdaTestDriver have built-in functions to do just that.
[EDIT] This project allows to record JDBC operations with later playback: http://sourceforge.net/projects/dbdatestdriver/