Unit testing JPA with different persistence.xml
已回答
I have an project I'm building with IntelliJ IDEA, a Tomcat based server using JPA and I'm adding unit tests.
I would like to run the unit tests with a different database and different settings than my main app, so I would like to have a main and a test version of the persistence.xml file. I have these two files:
src/main/resources/META-INF/persistence.xml
src/test/resources/META-INF/persistence.xml
But when I run the tests, it's always using the main one, not the test one. I believe I have the Content Roots set up correctly, with src/test/resources in Test Resource Folders.
I'm using IntelliJ's internal build. Is there a good way to do this?
Thanks
请先登录再写评论。
Is your project Maven based?
No, I'm not using any external build tools at the moment.
Test output folders are added to classpath before production output folders, so persistence.xml from test/resources should be found on classpath first. Do you have different output paths for production and tests on 'Paths' tab in the module editor in 'Project Structure' dialog?