I run the same tests from both eclipse and from an Ant task. When running from eclipse all tests pass. When I run Ant junit task, one, single test fails with the following strange error:
junit.framework.AssertionFailedError at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:423) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:137) at unitests.mypackage.MyTestClass.myTestCase(Unknown Source)
What can be the cause?
I read a little and found out that it might be because eclipse and Ant use different versions of junit. In my project, junit is located at libs/junit-4.10.jar and referenced both in eclipse's .classpath file and in junit task classpath. You can see Ant's task here:
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
<fileset dir="${src.dir}" includes="**/*.jar"/>
</path>
...
<target name="run-unit-tests" depends="compile,compile-unit-tests">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="yes" haltonfailure="no">
<classpath>
<path refid="classpath"/>
<fileset dir="${unit.tests.classes.dir}" includes="**/*.class"/>
</classpath>
<formatter type="xml"/>
<batchtest todir="${junit.output.dir}">
<fileset dir="${unit.tests.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
<mkdir dir="${junit.report.dir}"/>
<junitreport todir="${junit.report.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.report.dir}/html"/>
</junitreport>
</target>
The version of Ant is 1.7.1 and it came with eclipse.
Edit:
Eventually solved it by adding fork="yes
" to junit's task. Found it by generating build file using eclipse's export option, and then looking at the differences between the generated file and mine. No idea why forking solves the problem though.