I have a Spring + JPA + Hibernate application that I'm trying to test by subclassing code>AbstractJUnit4SpringContextTests. The class allows to specify the Spring context file using the @ContextConfiguration
annotation. In this file, the database is created and initialized (schema + data) using SQL scripts through the <jdbc:embedded-database>
element.
Now I have two classes that load two different spring context files, but they both contain this element. If I run each test class individually, all the test methods work fine. However, if I run them from an ant script, the second test that runs will complain because the database was already initialized! This is very odd as I have fork="yes" forkmode="perTest"
in my Ant JUnit target. I'm not sure why this is happening. Any ideas?
EDIT: here's a fragment of my ant script:
<junit printsummary="withOutAndErr" haltonfailure="yes" fork="yes" forkmode="perTest" maxmemory="512m">
<classpath refid="mvn.classpath"/>
<classpath location="${classes-core}"/>
<classpath location="${classes-pentaho}"/>
<classpath location="${classes-plugins}"/>
<classpath location="${junit.classes}"/>
<classpath location="${junit.resources}"/>
<sysproperty key="ant.home" value="${ant.home}"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out.dir.xml}">
<fileset dir="${junit.classes}" includes="**/*TestSuite.class"/>
</batchtest>
</junit>
Thanks
Giovanni