我的问题是:如何创建 Android独立的Android 库的测试项目?
我有我的安卓机library(在项目设置中标记为“库”)和一个包含我的 JUnit 测试类的 Android 项目。这test项目正确引用了 Android 库(在“Android”下的项目设置中)。
My library源代码位于包中com.mayastudios
。我的所有测试用例也位于同一个包中(但在不同的项目中)。所以基本上我有这样的东西:
+- MyLibraryProject
+- src
+- com/mayastudios/MyClass.java
+- AndroidManifest.xml
+- ...
+- MyTestProject (references MyLibraryProject)
+- test
+- com/mayastudios/MyClassTests.java
+- AndroidManifest.xml
+- ...
这是 Android 清单test项目:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spatialite.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.mayastudios" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:label="Spatialite-NewApi-UnitTests">
<uses-library android:name="android.test.runner" />
</application>
</manifest>
但是,当我运行test项目(来自带有 ADT 的 Eclipse,使用“运行方式 -> Android JUnit 测试”)我收到以下错误:
Unable to find instrumentation target package: com.mayastudios
这是完整的控制台日志:
[2012-04-24 17:24:20 - spatialite-test] Android Launch!
[2012-04-24 17:24:20 - spatialite-test] adb is running normally.
[2012-04-24 17:24:20 - spatialite-test] Performing android.test.InstrumentationTestRunner JUnit launch
[2012-04-24 17:24:20 - spatialite-test] Automatic Target Mode: using device '3732FBC2711300EC'
[2012-04-24 17:24:20 - spatialite-test] Uploading spatialite-test.apk onto device '3732FBC2711300EC'
[2012-04-24 17:24:20 - spatialite-test] Installing spatialite-test.apk...
[2012-04-24 17:24:22 - spatialite-test] Success!
[2012-04-24 17:24:22 - spatialite-test] Launching instrumentation android.test.InstrumentationTestRunner on device 3732FBC2711300EC
[2012-04-24 17:24:22 - spatialite-test] Collecting test information
[2012-04-24 17:24:23 - spatialite-test] Test run failed: Unable to find instrumentation target package: com.mayastudios
我尝试删除<instrumentation>
清单中的标记不起作用。
到目前为止,我实现此工作的唯一方法是创建一个默认的 Android 项目(带有 Activity),从我的测试项目中引用它,并使用此默认 Android 项目的包名称作为targetPackage
under <instrumentation>
。但这不是我想要的。我想要一个独立的测试项目。
有什么建议么?