简体   繁体   中英

Using a different persistence.xml file in tests with Arquillian

I am using a standard Maven project and I have one persistence.xml in the java resources folder and another persistence.xml in the test folder. How can I use the persistence.xml from the test folder in the arquillian test? Or isn't that a normal thing to do?

How can I use the persistence.xml from the test folder in the arquillian test?

You can construct a ShrinkWrap deployment for your test that packages the persistence.xml file of your test resources, instead of the main resource. You may reference it as such, in your @Deployment method:

addAsManifestResource("persistence.xml", new File("src/test/resources/persistence.xml"))

Or isn't that a normal thing to do?

Its an acceptable thing to do. But, with the Arquillian Persistence Extension, you should be able to use the persistence.xml file of your main resource, since the persistence unit will be managed by the container and the underlying datasource would be available to the JPA provider at runtime.

Using a test-only persistence.xml is usually done for instances where you want a persistence unit of transaction type RESOURCE_LOCAL instead of JTA, to enable testing of the persistence-unit outside the container.

there is a line in your code where you define what persistence file you are using. find it (using Cf on most platforms) and change it.

它也应该可以像这样添加:

.addAsResource("test-persistence.xml", "META-INF/persistence.xml")

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