title: Running unit tests with ant on an eclipse project
body: <p>Alright, so I've spent a good 3 days now combing the net trying to figure out how to run some unit tests with ant from the command line for my eclipse project.</p>
  
  <p>I can run the tests in Eclipse via "Run As" -> "Android JUnit Test"</p>
  
  <p>What I want now is to be able to run the tests via the command line. That's it.</p>
  
  <p>I can't seem to find any guides on this that were not written in 2010, but trying to follow them nonetheless I have gotten as far as installing ant and creating a build.xml file inside my project that I copy-pasta'd from a guide. Since I can only guess at what is going on in the build file (have never worked with ant before), when a problem rears its ugly head I'm pretty much SOL.</p>
  
  <p>Currently when I try and run it, it says "package android.app does not exist" (I'm using the Activity class), and the same for a library jar file I've included in the project's "/libs" folder.</p>
  
  <p>It seems pretty clear that somewhere I'm missing some kind of path declaration, but nothing I try seems to work.</p>
  
  <p>EDIT (added code):
  This is MockTester.java -</p>
  
  <pre><code>package com.android.mocksdktester;
  
  import static org.junit.Assert.*;
  import android.app.Activity;    
  import android.test.AndroidTestCase;
  
  import com.mock.android.lib.*;
  
  public class MockTester extends AndroidTestCase
  {
      Activity mActivity;
      MockFeature mFeature;
  
      public MockTester()
      {   
      }
  
  
      public void testExists()
      {
          String test = null;
          assertNull(test);
      }
  }
  </code></pre>
  
  <p>As you can see, not a lot going on. 
  This is the build.xml file I've got, and as I mentioned, I can only make guesses as to what it's doing.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!-- to save as "build.xml" --&gt;
  &lt;project name="Mock Unit Tests" default="run" basedir="."&gt;
      &lt;path id="junit_classpath"&gt; 
          &lt;pathelement location="C:\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705\junit.jar"/&gt;
      &lt;/path&gt;
  
      &lt;!-- Library Project Here --&gt;
      &lt;fileset dir="libs" includes="*.jar"/&gt;
  
  
      &lt;!-- build all classes in this directory --&gt;
      &lt;!-- To run this: use "ant build" --&gt;
      &lt;!-- need to include junit.jar in the classpath --&gt;
      &lt;target name="build"&gt;   
          &lt;javac srcdir="${basedir}"/&gt;
          &lt;echo message="Build done" /&gt;
      &lt;/target&gt;
  
      &lt;!-- Test and build all files  --&gt;
      &lt;!-- To run this: use "ant" (default) or "ant run" --&gt;
      &lt;target name="run" depends="build"&gt;
          &lt;java taskname="Test" classname="MockTester" fork="true" failonerror="true" /&gt;
          &lt;echo message="Unit Tests done" /&gt;
      &lt;/target&gt;
  
      &lt;!-- delete all class files --&gt;
      &lt;!-- To run this: use "ant clean" --&gt;
      &lt;target name="clean"&gt;
          &lt;delete&gt;
              &lt;fileset dir="${basedir}" includes="*.class" /&gt;
          &lt;/delete&gt;
          &lt;echo message="clean done" /&gt;
      &lt;/target&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>It was complaining about not seeing junit in the past but I managed to fix that. I'm just not sure what to do when it's missing Android-related classes, and a jar file included in the project (though I've read this is a bug).</p>
  
  <p>Errors:</p>
  
  <pre><code>build:
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\build.xml:16: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
  [javac] Compiling 3 source files
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:14:error: package android.app does not exist
  [javac] import android.app.Activity;
  [javac]                   ^
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:15:error: package android.test does not exist
  [javac] import android.test.AndroidTestCase;
  [javac]                    ^
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:18:error: package com.mock.android.lib does not exist
  [javac] import com.mock.android.lib.*;
  [javac] ^
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:20:error: cannot find symbol
  [javac] public class MockTester extends AndroidTestCase
  [javac]                                  ^
  [javac]   symbol: class AndroidTestCase
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:22:error: cannot find symbol
  [javac]     Activity mActivity;
  [javac]     ^
  [javac]   symbol:   class Activity
  [javac]   location: class MockTester
  [javac] C:\&lt;my workspace&gt;\mock\mock_sdk_android\trunk\source\MockSDKTest\src\com\android\mocksdktester\MockTester.java:23:error: cannot find symbol
  [javac]     MockFeature mFeature;
  [javac]     ^
  [javac]   symbol:   class MockFeature
  [javac]   location: class MockTester
  [javac] 6 errors
  
  BUILD FAILED
  </code></pre>
  
  <p>Thanks</p>