OSDN Git Service

ENHANCEMENT: activitycreator generates 'tests' project for instrumentation.
authorMuthu Ramadoss <muthu.ramadoss@gmail.com>
Thu, 13 Nov 2008 10:06:09 +0000 (15:36 +0530)
committerMuthu Ramadoss <muthu.ramadoss@gmail.com>
Fri, 14 Nov 2008 07:52:05 +0000 (13:22 +0530)
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.

scripts/AndroidManifest.tests.template [new file with mode: 0644]
scripts/build.template
scripts/java_tests_file.template [new file with mode: 0644]

diff --git a/scripts/AndroidManifest.tests.template b/scripts/AndroidManifest.tests.template
new file mode 100644 (file)
index 0000000..1f7d827
--- /dev/null
@@ -0,0 +1,21 @@
+<?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>
index 74e8453..9aeaf98 100644 (file)
@@ -20,7 +20,8 @@
     <!-- 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>
diff --git a/scripts/java_tests_file.template b/scripts/java_tests_file.template
new file mode 100644 (file)
index 0000000..7781a33
--- /dev/null
@@ -0,0 +1,21 @@
+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