activitycreator script is enhanced to generate 'tests' project along with the main project. The current behavior of generating Activity is extended by generating ActivityTest in 'tests/src' folder. The 'tests' folder follows the example provided asis in 'ApiDemos'. ApiDemos was used as reference project to mimic the project layout for building tests using Instrumentation.
From 'tests' project, type:
"adb shell am instrument -w [your.package].tests/android.test.InstrumentationTestRunner"
to run all tests using Android InstrumentationTestRunner.
NOTE: 'tests' is a separate AndroidProject by all means. It has its own AndroidManifest.xml, build.xml, src, res etc.,
AMEND:
Fixed style issues, javadoc
Fixed build.template to generate tests/build.xml
Removed build.tests.template since its obsolete now.
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="PACKAGE.tests"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <!-- We add an application tag here just so that we can indicate that
+ this package needs to link against the android.test library,
+ which is needed when building test cases. -->
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+ <!--
+ This declares that this application uses the instrumentation test runner targeting
+ the package of PACKAGE. To run the tests use the command:
+ "adb shell am instrument -w PACKAGE.tests/android.test.InstrumentationTestRunner"
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="PACKAGE"
+ android:label="Tests for ACTIVITY_NAME"/>
+</manifest>
<!-- The intermediates directory, Eclipse uses "bin"
for its own output, so we do the same. -->
<property name="outdir" value="bin" />
-
+ <property name="outdir-main" value="../${outdir}" />
+
<!-- ************************************************************************************* -->
<!-- No user servicable parts below. -->
else="${basedir}/${outdir-classes}" >
<os family="windows"/>
</condition>
+ <condition property="outdir-main-classes"
+ value="${outdir-main}/classes">
+ <available file="${outdir-main}/classes"
+ type="dir"/>
+ </condition>
<!-- Create R.java in the source directory -->
<property name="outdir-r" value="src" />
bootclasspath="${android-jar}">
<classpath>
<fileset dir="${external-libs}" includes="*.jar"/>
+ <pathelement path="${outdir-main-classes}"/>
</classpath>
</javac>
</target>
--- /dev/null
+package PACKAGE;
+
+import android.test.ActivityInstrumentationTestCase;
+
+/**
+ * This is a simple framework for a test of an Application. See
+ * {@link android.test.ApplicationTestCase ApplicationTestCase} for more information on
+ * how to write and extend Application tests.
+ * <p/>
+ * To run this test, you can type:
+ * adb shell am instrument -w \
+ * -e class PACKAGE.ACTIVITY_NAMETest \
+ * PACKAGE.tests/android.test.InstrumentationTestRunner
+ */
+public class ACTIVITY_NAMETest extends ActivityInstrumentationTestCase<ACTIVITY_NAME> {
+
+ public ACTIVITY_NAMETest() {
+ super("PACKAGE", ACTIVITY_NAME.class);
+ }
+
+}
\ No newline at end of file