I've just given the Alpha 4 release of the Arquillian Persistence Extension a go to see if it'll help simplify my database tests. After initial testing I have a few comments and questions.
Most importantly, is it really a good idea to have the database "cleaned" by default? Deleting from all tables does not, to me, conform to the principle of least surprise. If you want a temporary DB you're often using an in-mem h2 or something anyway. More importantly, it's a really unsafe default, especially because a mistake in supplying a datasource could have very nasty results. Sure, your test environment should be completely separate to your production env with no risk of data loss, but in reality not everyone's going to set it up that way. I think this default should be changed as a matter of urgency before 1.0.
One thing I noticed in the docs: it took me a while to correctly place my @ApplyScriptBefore and @ApplyScriptAfter . The docs just said the "scripts" directory; this turns out to be "scripts/" on the classpath of the deployed archive, ie src/test/resources/scripts . I've submitted an edit to make this more explicit.
For some reason my tests don't appear to see/respect the defaultDataSource in arquillian.xml (src/test/resources/arquillian.xml). This config still results in an exception thrown by seam persistence, complaining that the datasource isn't provided.
<?xml version="1.0" encoding="UTF-8"?> <arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <extension qualifier="persistence"> <property name="defaultDataSource">java:/datasources/some-test-ds</property> <property name="userTransactionJndi">java:jboss/UserTransaction</property> <property name="alwaysExcludeFromDataSetsComparision">id</property> </extension> <container qualifier="jboss7remote" default="true"> <configuration> <property name="managementAddress">127.0.0.1</property> <property name="managementPort">9999</property> </configuration> </container> </arquillian>
Tests fail with:
org.jboss.arquillian.persistence.exception.DataSourceNotDefinedException: DataSource not defined! Please declare in arquillian.xml or by using @DataSource annotation.
I've tried adding arquillian.xml to my ShrinkWrap archives (WarArchive format) using addAsResource( ) and addAsWebInfResource( ) as I wasn't sure where arq would be looking for the config within a deployed archive. Neither had any effect. Ideas?