title: JUnit test fails in Ant with `<junit>` task but passes with `<exec>`?
body: <p>I am automating my JUnit tests into my Ant build. However, my simple test only passes when run from the IDE and commandline but fails with Ant's <code>&lt;junit&gt;</code> task. When I run it from the commandline (I am technically using the Ant <code>&lt;exec&gt;</code> task) the result is:</p>
  
  <pre><code>clean:
  
  compile_tests:
      [javac] Compiling 2 source files to C:\MY_TEMP
  
  junit_exec:
       [exec] JUnit version 4.10
       [exec] .
       [exec] Time: 0.004
       [exec]
       [exec] OK (1 test)
       [exec]
  
  BUILD SUCCESSFUL
  Total time: 1 second
  </code></pre>
  
  <p>but when I use the <code>&lt;junit&gt;</code> task:</p>
  
  <pre><code>Buildfile: C:\MY_TEMP\build.xml
  
  clean:
  
  compile_tests:
      [javac] Compiling 2 source files to C:\MY_TEMP
  
  junit_ant:
       [echo] junit_ant started
      [junit] Test SimpleTest FAILED
  
  BUILD SUCCESSFUL
  Total time: 0 seconds
  </code></pre>
  
  <p>The contents of <code>MY_TEMP</code> are <code>junit-4.10.jar</code>, <code>SimpleTest.java</code>, and <code>build.xml</code>.</p>
  
  <p>I have copied <code>junit-4.10.jar</code> to the <code>%ANT_HOME%\lib</code> folder as suggest by the <a href="http://ant.apache.org/manual/Tasks/junit.html" rel="nofollow">Ant junit task documentation</a>. It already had both <code>ant-junit.jar</code> and <code>ant-junit4.jar</code>.</p>
  
  <p>My version of Java is 1.6.0_26.</p>
  
  <p>My test is: </p>
  
  <pre><code>// YES, this is the default package
  import org.junit.*;
  
  public class SimpleTest {
  
      @Test
      public void mySimpleTest(){
          Assert.assertEquals(  2,  1 + 1  );
      }
  
  }
  </code></pre>
  
  <p>And my Ant file (build.xml ), is:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project name="regression_tests" basedir="."&gt;
  
      &lt;target name="clean"&gt;
          &lt;delete&gt;
              &lt;fileset dir="." includes="*.class" /&gt;
          &lt;/delete&gt;
      &lt;/target&gt;
  
      &lt;target name="compile_tests" depends="clean"&gt;
              &lt;javac srcdir="." destdir="." source="1.6" target="1.6" includeantruntime="false" &gt;
              &lt;classpath&gt;
                  &lt;pathelement location="./junit-4.10.jar" /&gt;
              &lt;/classpath&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="junit_ant" depends="compile_tests" &gt;
          &lt;echo message="junit_ant started" /&gt;
  
          &lt;junit&gt;
              &lt;test name="SimpleTest" /&gt;
          &lt;/junit&gt;
      &lt;/target&gt;
  
      &lt;target name="junit_exec" depends="compile_tests"&gt;
          &lt;exec executable="java" dir="." &gt;
              &lt;arg value="-classpath" /&gt;
              &lt;arg value=".;junit-4.10.jar" /&gt;
              &lt;arg value="org.junit.runner.JUnitCore" /&gt;
              &lt;arg value="SimpleTest" /&gt;
          &lt;/exec&gt;
      &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>