简体   繁体   中英

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...

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.

您需要使用2套spring config文件或配置类,并在单元测试中引用测试配置文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM