Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit test fails only when running from with Ant task
    primarykey
    data
    text
    <p>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:</p> <blockquote> <p>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)</p> </blockquote> <p>What can be the cause? </p> <p>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:</p> <pre><code>&lt;path id="classpath"&gt; &lt;fileset dir="${lib.dir}" includes="**/*.jar"/&gt; &lt;fileset dir="${src.dir}" includes="**/*.jar"/&gt; &lt;/path&gt; ... &lt;target name="run-unit-tests" depends="compile,compile-unit-tests"&gt; &lt;mkdir dir="${junit.output.dir}"/&gt; &lt;junit fork="yes" printsummary="yes" haltonfailure="no"&gt; &lt;classpath&gt; &lt;path refid="classpath"/&gt; &lt;fileset dir="${unit.tests.classes.dir}" includes="**/*.class"/&gt; &lt;/classpath&gt; &lt;formatter type="xml"/&gt; &lt;batchtest todir="${junit.output.dir}"&gt; &lt;fileset dir="${unit.tests.dir}"&gt; &lt;include name="**/*Test*.java"/&gt; &lt;/fileset&gt; &lt;/batchtest&gt; &lt;/junit&gt; &lt;mkdir dir="${junit.report.dir}"/&gt; &lt;junitreport todir="${junit.report.dir}"&gt; &lt;fileset dir="${junit.output.dir}"&gt; &lt;include name="TEST-*.xml"/&gt; &lt;/fileset&gt; &lt;report format="frames" todir="${junit.report.dir}/html"/&gt; &lt;/junitreport&gt; &lt;/target&gt; </code></pre> <p>The version of Ant is 1.7.1 and it came with eclipse.</p> <p><strong>Edit:</strong></p> <p>Eventually solved it by adding <code>fork="yes</code>" 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload