user1071914
user1071914

Reputation: 3403

Best way to clone existing DB for Junit tests?

I have to clone tables from an existing database somehow in order to run unit tests. The ideal solution would be something - a Maven plugin or Spring bean - that would clone the database tables into a HSQL database, which I could then hit with my JUnit tests.

What is the most straightforward way to do this?

Upvotes: 0

Views: 441

Answers (1)

Matthew Mark Miller
Matthew Mark Miller

Reputation: 3168

Download DBUnit. http://dbunit.sourceforge.net/

Export a dataset from your existing DB to XML.

In your suite, import the dataset into HSQL.

You're going to want to get to know DBUnit if you intend to unit test an app whose behavior is tightly coupled with its persistence layer (e.g. anything written in ORM).

Upvotes: 3

Related Questions