我想你会在一月份解决它,但我使用命令行工具,发现了类似的问题(错误消息不同)并像我在以下步骤中解释的那样解决了它。我完成了从创建一个带有空测试的虚拟项目到成功测试运行的整个过程。我希望它对某人有用:
第一步,创建项目:
android create project
--name MyExample
--target "Google Inc.:Google APIs:17"
--path MyExample
--package com.example
--activity MyExampleActivity
第二步,创建测试项目:
android create test-project
--path MyExampleTest
--name MyExampleTest
--main ../MyExample
第三步,访问你的项目目录,构建它并检查过程是否成功结束:
cd MyExample && ant debug
第四步,安装到模拟器:
adb -s emulator-5554 install -r bin/MyExample-debug.apk
第五步,访问你的测试项目目录并尝试运行测试:
cd ../MyExampleTest &&
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
这会产生:
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.example.tests/android.test.InstrumentationTestRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.example.tests/android.test.InstrumentationTestRunner
at com.android.commands.am.Am.runInstrument(Am.java:676)
at com.android.commands.am.Am.run(Am.java:119)
at com.android.commands.am.Am.main(Am.java:82)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
at dalvik.system.NativeStart.main(Native Method)
第六步,列出你的检测类并确保你当前的项目缺失:
adb shell pm list instrumentation
在我的机器中产生:
instrumentation:com.android.emulator.connectivity.test/android.test.InstrumentationTestRunner (target=com.android.emulator.connectivity.test)
instrumentation:com.android.emulator.gps.test/android.test.InstrumentationTestRunner (target=com.android.emulator.gps.test)
instrumentation:com.android.example.spinner.tests/android.test.InstrumentationTestRunner (target=com.android.example.spinner)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.android.smoketest.tests/android.test.InstrumentationTestRunner (target=com.android.smoketest)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
如您所见,仪器com.example.tests
不存在,因此我们必须创建它。
第七步,构建你的测试项目并检查它是否成功:
ant debug
第八步,安装到模拟器:
adb -s emulator-5554 install -r bin/MyExampleTest-debug.apk
第九步,列出您的仪器类并查找您的项目之一:
adb shell pm list instrumentation
这会产生:
instrumentation:com.android.emulator.connectivity.test/android.test.InstrumentationTestRunner (target=com.android.emulator.connectivity.test)
instrumentation:com.android.emulator.gps.test/android.test.InstrumentationTestRunner (target=com.android.emulator.gps.test)
instrumentation:com.android.example.spinner.tests/android.test.InstrumentationTestRunner (target=com.android.example.spinner)
instrumentation:com.android.smoketest.tests/com.android.smoketest.SmokeTestRunner (target=com.android.smoketest)
instrumentation:com.android.smoketest.tests/android.test.InstrumentationTestRunner (target=com.android.smoketest)
instrumentation:com.example.tests/android.test.InstrumentationTestRunner (target=com.example)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
看倒数第二个instrumentation:com.example.tests
,这是我们想要的。
第十步,运行你的测试:
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
这会产生:
Test results for InstrumentationTestRunner=
Time: 0.0
OK (0 tests)
就这些。现在实现你的测试,像往常一样编译和安装。此外,您可以像这样删除它们:
adb shell pm uninstall com.example.tests
但是您将需要再次创建检测类以避免相同的错误。