DBUnit and CLEAN_INSERT
A few days ago I was trying to hook DBUnit into my test process so that my database would contain the same data before my JUnit tests are run. I had some issues getting it to work and later found that there was a bug in DBUnit's ant task. Basically, it was not allowing me to disable batch statements. Anyway, it's been fixed in CVS and now my JUnit tests (all run through a common test-module task) depend on a "db-load" task. Pretty cool and awful easy to configure. I'll be updating struts-resume/appfuse in the next few days to contain this slick trick. In the meantime, here's my db-load target. The file sample-data.xml
is also built using Ant via DBUnit's "export" task.
<target name="db-load" description="Loads database from exported DBUnit file"> <property name="operation" value="CLEAN_INSERT"/> <property name="file" value="metadata/sql/sample-data.xml"/> <dbunit driver="${hibernate.connection.driver_class}" supportBatchStatement="false" url="${hibernate.connection.url}" userid="${hibernate.connection.username}" password="${hibernate.connection.password}" schema="${hibernate.connection.schema}"> <operation type="${operation}" src="${file}" format="xml"/> </dbunit> </target>