unit testing - How to execute sql-script file using hibernate? -
i gonna write several intergration tests test interatcion db. each test need have snapshot of db. each db snapshot saved in .sql file. want execute script file in test method, this:
@test public void test_stuff(){ executescript(finame.sql); ... testing logic ... clean_database(); }
does hibernate has means this?
you can automatically execute sql script @ startup of hibernate: write sql commands in file called import.sql , put in root of classpath.
you don't need clean database test, make test transactional rollback @ end of each test. hence, sure database not contaminated tests. instance, using spring:
@transactional @transactionconfiguration public class mytest { ... }
if don't use spring, try test framework default-rollback transaction support.
Comments
Post a Comment