- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个简单的 android 应用程序,我正在使用我的手机对其进行测试。所以,有两种方法可以做到这一点:
问题:
当我使用 Eclipse 运行单元测试用例时,它会在运行时在我的手机上安装应用程序并运行 junit test,然后如果我在 CLI 上使用命令:adb -d shell am instrument -w com.abc.xyz.test/android.test.InstrumentationTestRunner,它运行良好。
但是,如果我直接在 CLI 中运行上述命令而没有先在 Eclipse 中运行单元测试用例,则会出现错误:
android.util.AndroidException: INSTRUMENTATION_FAILED: com.abc.xyz.test/android.test.InstrumentationTestRunner at com.android.commands.am.Am.runInstrument(Am.java:586) at com.android.commands.am.Am.run(Am.java:117) at com.android.commands.am.Am.main(Am.java:80) at com.android.internal.os.RuntimeInit.finishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:263) at dalvik.system.NativeStart.main(Native Method)INSTRUMENTATION_STATUS: id=ActivityManagerServiceINSTRUMENTATION_STATUS: Error=Unable to find instrumentation target package: com.abc.xyzINSTRUMENTATION_STATUS_CODE: -1
AndroidMAnifest.xml contains:
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.abc.xyz"
inside instrumentation tag
谁能帮帮我
最佳答案
我想你会在一月份解决它,但是我使用命令行工具,发现了类似的问题(错误消息不同)并像我在以下步骤中解释的那样解决了它。我完成了从创建一个带有空测试的虚拟项目到成功测试运行的整个过程。我希望它对某人有用:
第一步,创建项目:
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)
第六步,列出你的instrumentation clases并确保你当前的项目缺失:
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
但您需要再次创建检测类以避免同样的错误。
关于android.util.AndroidException : INSTRUMENTATION_FAILED:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14269687/
Armandos-MacBook-Air:cucumber armando.rodriguez$ calabash-android run m ......apk找不到此应用程序和葫芦版本组合的测试服
我有一个简单的 android 应用程序,我正在使用我的手机对其进行测试。所以,有两种方法可以做到这一点: 使用 eclipse 使用 CLI 问题: 当我使用 Eclipse 运行单元测试用例时,它
情况如下。我使用 Jenkins 2.32.2 创建了一个 headless 的 Ubuntu 16.04 Docker 容器,目前是 openjdk 1.8.0_121 以及 JDK 7u80(JD
我是一名优秀的程序员,十分优秀!