I have a unit test that contains 6 test cases (@Test-annotated methods) that all run perfectly when I run the Java file as a JUnit Test (from inside Eclipse workbench). But when I go to run a run-tests Ant target from a buildscript, they fail with the following console output:
[junit] Running com.me.myproject.WidgetTest
[junit] Tests run: 6, Failures: 6, Errors: 0, Time elapsed: 1.737 sec
[junit] Test com.me.myproject.WidgetTest FAILED
Here is the JUnit section of the run-tests target:
<junit fork="yes" forkmode="once" dir="${basedir}" printsummary="yes" haltonerror="no" haltonfailure="no">
<classpath>
<path refid="test.class.path"/>
<pathelement location="${mainBuildDir}"/>
<pathelement location="${testBuildDir}"/>
</classpath>
<formatter type="xml"/>
<batchtest todir="${genUnitTestReportsDir}">
<fileset dir="${testJavaSrcDir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
Anybody ever hear of this happening? Is there any way to get more (verbose) output from JUnit’s ant task? Any good way to debug what’s happening here? Thanks in advance!
I have had similar problems with classes that write to databases when using Hibernate/Hypersonic SQL for my tests. The life of the Hypersonic connection when running tests inside eclipse is much shorter than the one used by ant. As a result, the databases are deleted at the end of every test in Eclipse, but stick around from test to test inside ant.
If you write data in your databases, you need to delete them in the tear down to ensure the next test won’t pick up your data.