Unit testing JPA with different persistence.xml

Answered

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

 

 

0
3 comments

Is your project Maven based?

0
Avatar
Permanently deleted user

No, I'm not using any external build tools at the moment.

 

0

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? 

0

Please sign in to leave a comment.