java - Setup and Tear Down of Complex Database State With Hibernate / Spring / JUnit -
I have a class that I am testing a unit for which quite different before running different test methods Database setup is required. This setup takes a long time: Due to the hope that manual is not relevant to the question, I would have to programmatically populate the DB program instead of the SQL dump.
I have trouble with tear-down, how can I easily return all the changes made in the DB setup step?
I am currently using Hibernate + Spring Transactional Testing Support, as if my personal testing methods are wrapped in transactions.
One solution must be to setup DB within each test method, such as DB setup will be automatically returned. However, test methods are always carried out to run because each method will need to be re-submitted to the database.
Any other ideas? In fact, I'm looking for a way to run my DB setup, run my personal tests (wrapped in each transaction, rolled after execution), and then roll-back the initial DB setup Hibernate / Spring / Any ideas about working in junit fashion? Is there any hibernate equivalent to "all tables drop"?
Are you stuck with a specific database vendor? If not, you can use an in-memory database, such as When you are done with trials, you just throw the state. This is only suitable if tables can be empty at the beginning of the Tables Suite (before your programmatic setup, that is).
You still need to create tables, but if everything can be used in hibernate way, hibm2ddl can be used to generate their tables. You only need to add the following in your test session factory definition:
& lt; Session-factory & gt; ... & lt; Property Name = "hibernate.hbm2ddl.auto" & gt; Create & lt; / Property & gt; ... & lt; / Session-factory & gt; If this solution applies, then I can expand it.
Comments
Post a Comment