Testing with MavenSome of us find maven extremely usefull. To be able to test your hibernate stuff inside maven project you will need proper dependency for hibernate version of your choice ( I assume you already have this, or you will be unable to compile ) First step is telling your maven what resources shall be present while testing. This example lets maven include xdoclet generated mappings into junit inviocation classpath. Your directories may vary. ( from project.xml )
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<resources>
<resource>
<directory>${maven.build.dir}/xdoclet/hibernatedoclet</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/conf</directory>
<includes>
<include>hibernate.properties</include>
</includes>
</resource>
<resource>
<directory>${pom.build.unitTestSourceDirectory}</directory>
<includes>
<include>**/*.dat</include>
<include>**/*.txt</include>
<include>**/*.h</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</unitTest>
It's also cool to configure log4j properly, to be able to see what's going on. ( from project.properties )
#setup for junit testing
maven.junit.sysproperties=log4j.configuration
log4j.configuration=log4j.properties
I prefer to test against hsqldb ( where possible ) because it leaves nice SQL traace after running. So my hibernate properties look like:
hibernate.show_sql=false
hibernate.use_outer_join=true
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:foo
hibernate.connection.username=sa
hibernate.dialect=cirrus.hibernate.sql.HSQLDialect
And database script can be found in current directory under name "foo.script". But remember, in this case you may have to take care of dropping and creating tables at appropriate times.
|