Hello,
I've got a project laid out like so:
|-- Android.mk
|-- AndroidManifest.xml
`-- java
`-- com
`-- foo
|-- Foo.java
`-- FooTest.java
Foo is a simple class. It does not extend Activity or Application.
FooTest.java extends TestCase class. I successfully run the tests
like so:
$ adb shell am instrument -w com.foo/android.test.InstrumentationTestRunner
Test results for InstrumentationTestRunner=
Time: 0.001
OK (0 tests)
Hooray! Now I want to move FooTest.java into a tests/ directory so
the tree looks like this:
|-- Android.mk
|-- AndroidManifest.xml
|-- java
| `-- com
| `-- foo
| `-- Foo.java
`-- tests
|-- Android.mk
|-- AndroidManifest.xml
`-- java
`-- com
`-- foo
`-- FooTest.java
Everything builds fine, but I get a runtime error when I try to run the tests:
adb shell am instrument -w com.foo.tests/android.test.InstrumentationTestRunner
INSTRUMENTATION_RESULT: shortMsg=Unable to instantiate instrumentation
ComponentInfo{com.foo.tests/android.test.InstrumentationTestRunner}:
java.lang.ClassNotFoundException:
android.test.InstrumentationTestRunner in loader
dalvik.system.PathClassLoader@4001ada0
INSTRUMENTATION_RESULT: longMsg=java.lang.RuntimeException: Unable to
instantiate instrumentation
ComponentInfo{com.foo.tests/android.test.InstrumentationTestRunner}:
java.lang.ClassNotFoundException:
android.test.InstrumentationTestRunner in loader
dalvik.system.PathClassLoader@4001ada0
INSTRUMENTATION_CODE: 0
I'm pretty sure I'm missing something simple. Below are the
Android.mk and AndroidManifest.xml files from the failing source tree.
Please help!
$ cat Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng user
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_PACKAGE_NAME := Foo
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
$ cat AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.foo">
</manifest>
$ cat tests/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_PACKAGE_NAME := FooTests
LOCAL_INSTRUMENTATION_FOR := Foo
LOCAL_SDK_VERSION := current
include $(BUILD_PACKAGE)
$ cat tests/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.foo.tests">
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.foo"
android:label="Foo Tests."/>
</manifest>