nashuald
nashuald

Reputation: 825

How to do tests with JPA and JUnit on differents persistence units?

I am very new using JUnit. I want to test some classes that implements JPA. But, I have two databases, one for testing and other for development.

Normally, the testing db is clean. I test inserts, updates, delets, so and so, but any time I have to switch the db connection to testing db.

How can I have two persistence units: one for testing and other for development?

Thanks...

Upvotes: 0

Views: 450

Answers (2)

James
James

Reputation: 18379

You can either have two different persistence units in your persistence.xml file, or you can have one, and create your EntityManagerFactory passing in a properties map that override the database parameters.

Your entities/mappings can be the same for both.

Upvotes: 1

FFL
FFL

Reputation: 669

You need to use 2 sets of spring config files or configuration classes and reference the test configuration files in the unit tests.

Upvotes: 0

Related Questions