1
votes

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!

2
The easiest way to debug is to add a bunch of System.out.println statements in your tests to see what's happening.yatskevich
BTW, take a look at showoutput parameter of junit Ant task. ant.apache.org/manual/Tasks/junit.htmlyatskevich
Do you have output for the failed tests?helios

2 Answers

0
votes

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.

0
votes

I can't tell without seeing the stacktrace of the exception occuring. It's probably a classpath issue. Check the Java ANT documentation about JUnit, it should help you to enable debug traces.