android.util.AndroidException:INSTRUMENTATION_FAILED: [英] android.util.AndroidException: INSTRUMENTATION_FAILED:
问题描述
我有一个简单的Android应用程序,我测试它用我的电话。因此,有两种方法可以做到这一点:
- 使用Eclipse
- 使用CLI
问题:
当我运行使用Eclipse的单元测试的情况下,它安装的应用程序在我的手机在运行时和运行JUnit测试之后,如果我用命令的命令行: 亚行-d壳上午仪器-w com.abc.xyz.test / android.test.InstrumentationTestRunner,它运行良好。
不过,如果我直接无需先运行单元测试用例在Eclipse中,我得到的错误运行CLI上面的命令:
android.util.AndroidException:INSTRUMENTATION_FAILED:com.abc.xyz.test / android.test.InstrumentationTestRunner 在com.android.commands.am.Am.runInstrument(Am.java:586) 在com.android.commands.am.Am.run(Am.java:117) 在com.android.commands.am.Am.main(Am.java:80) 在com.android.internal.os.RuntimeInit.finishInit(本机方法) 在com.android.internal.os.RuntimeInit.main(RuntimeInit.java:263) 在dalvik.system.NativeStart.main(本机方法) INSTRUMENTATION_STATUS:ID = ActivityManagerService INSTRUMENTATION_STATUS:错误=找不到仪表目标包:com.abc.xyz INSTRUMENTATION_STATUS_ code:-1
AndroidManifest.xml中包括:
安卓名=android.test.InstrumentationTestRunner
机器人:targetPackage =com.abc.xyz
内部仪表标签
任何人都可以请帮我
我想,你会自一月份以来解决了它,但我使用命令行工具的工作,发现了类似的问题(错误信息是不同的),并解决它像我在下面的步骤说明。我从创建它的空测试虚设项目,直到成功试运行的全过程。我希望它是有用的人:
第一步,创建项目:
的Android创建项目
--name myexample中
--target谷歌公司:谷歌的API:17
--path myexample中
--package com.example
--activity MyExampleActivity
第二步,创建测试项目:
安卓创建测试项目
--path MyExampleTest
--name MyExampleTest
- 主../MyExample
第三步,进入你的项目目录,建立它并检查过程顺利结束:
CD myexample中和放大器;&安培;蚂蚁调试
第四步,并将其安装到模拟器:
ADB -s模拟器-5554安装-r斌/ myexample中,debug.apk
第五步后,进入测试项目目录,并尝试运行测试:
CD ../MyExampleTest和放大器;&安培;
亚行外壳上午仪器-w com.example.tests / android.test.InstrumentationTestRunner
这产量:
INSTRUMENTATION_STATUS:ID = ActivityManagerService
INSTRUMENTATION_STATUS:错误=无法找到仪器仪表信息:ComponentInfo {com.example.tests / android.test.InstrumentationTestRunner}
INSTRUMENTATION_STATUS_ code:-1
android.util.AndroidException:INSTRUMENTATION_FAILED:com.example.tests / android.test.InstrumentationTestRunner
在com.android.commands.am.Am.runInstrument(Am.java:676)
在com.android.commands.am.Am.run(Am.java:119)
在com.android.commands.am.Am.main(Am.java:82)
在com.android.internal.os.RuntimeInit.nativeFinishInit(本机方法)
在com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
在dalvik.system.NativeStart.main(本机方法)
第六步,列出你的仪表clases并确保您的当前项目丢失:
亚行外壳时列表仪器
这是在我的机器收益率:
<$p$p><$c$c>instrumentation:com.android.emulator.connectivity.test/android.test.InstrumentationTestRunner (TARGET = com.android.emulator.connectivity.test) 仪器仪表:com.android.emulator.gps.test / android.test.InstrumentationTestRunner(目标= com.android.emulator.gps.test) 仪器仪表:com.android.example.spinner.tests / android.test.InstrumentationTestRunner(目标= com.android.example.spinner) 仪器仪表:com.android.smoketest.tests / com.android.smoketest.SmokeTestRunner(目标= com.android.smoketest) 仪器仪表:com.android.smoketest.tests / android.test.InstrumentationTestRunner(目标= com.android.smoketest) 仪器仪表:com.example.android.apis / .app.LocalSampleInstrumentation(目标= com.example.android.apis)
正如你所看到的,仪器仪表为 com.example.tests
不存在,所以我们必须创建它。
第七步,建立你的测试项目,并检查它是否成功所做的:
蚂蚁调试
附表8步,并将其安装到模拟器:
ADB -s模拟器-5554安装-r斌/ MyExampleTest,debug.apk
第九步,列出你的仪器仪表类,并期待为您的项目之一:
亚行外壳时列表仪器
这产量:
<$p$p><$c$c>instrumentation:com.android.emulator.connectivity.test/android.test.InstrumentationTestRunner (TARGET = com.android.emulator.connectivity.test) 仪器仪表:com.android.emulator.gps.test / android.test.InstrumentationTestRunner(目标= com.android.emulator.gps.test) 仪器仪表:com.android.example.spinner.tests / android.test.InstrumentationTestRunner(目标= com.android.example.spinner) 仪器仪表:com.android.smoketest.tests / com.android.smoketest.SmokeTestRunner(目标= com.android.smoketest) 仪器仪表:com.android.smoketest.tests / android.test.InstrumentationTestRunner(目标= com.android.smoketest) 仪器仪表:com.example.tests / android.test.InstrumentationTestRunner(目标= com.example) 仪器仪表:com.example.android.apis / .app.LocalSampleInstrumentation(目标= com.example.android.apis)
看倒数第二个,仪器仪表:com.example.tests
,这是我们想要的。
第十步,运行测试:
亚行外壳上午仪器-w com.example.tests / android.test.InstrumentationTestRunner
这产量:
测试结果InstrumentationTestRunner =
时间:0.0
OK(0测试)
这就是全部。现在,实现你的测试,编译和安装像往常一样。此外,您可以将其删除,如:
亚行外壳时卸载com.example.tests
但是,你需要重新创建仪表类,以避免同样的错误。
I have a simple android app and I am testing it using my phone. So, there are two ways to do that :
- Using eclipse
- Using CLI
Problem:
When I run unit test case using Eclipse, it installs app on my phone at runtime and run junit test and after that if I use command on CLI: adb -d shell am instrument -w com.abc.xyz.test/android.test.InstrumentationTestRunner, it runs fine.
However, if I directly run the above command in CLI without first running the unit test cases in Eclipse, I am getting error:
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=ActivityManagerService INSTRUMENTATION_STATUS: Error=Unable to find instrumentation target package: com.abc.xyz INSTRUMENTATION_STATUS_CODE: -1
AndroidMAnifest.xml contains:
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.abc.xyz"
inside instrumentation tag
Could anyone please help me
I suppose that you will have solved it since january, but I work with command-line tools, found similar problem (error message is different) and solved it like I explain in following steps. I do the whole process from creating a dummy project with its empty test until a successful test run. I hope it can be useful for someone:
First step, create the project:
android create project
--name MyExample
--target "Google Inc.:Google APIs:17"
--path MyExample
--package com.example
--activity MyExampleActivity
Second step, create test project:
android create test-project
--path MyExampleTest
--name MyExampleTest
--main ../MyExample
Third step, access to your project directory, build it and check that the process ends successfully:
cd MyExample && ant debug
Fourth step, install it to the emulator:
adb -s emulator-5554 install -r bin/MyExample-debug.apk
Fifth step, access to your test project directory and try to run the tests:
cd ../MyExampleTest &&
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
That yields:
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)
Sixth step, list your instrumentation clases and ensure that your current project is missing:
adb shell pm list instrumentation
That in my machine yields:
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)
As you can see, the instrumentation for com.example.tests
doesn't exist, so we will have to create it.
Seventh step, build you test project and check that it did successfully:
ant debug
Eigth step, install it to the emulator:
adb -s emulator-5554 install -r bin/MyExampleTest-debug.apk
Ninth step, list your instrumentation classes and look for the one of your project:
adb shell pm list instrumentation
That yields:
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)
Look at the second to last, instrumentation:com.example.tests
, it's which we wanted.
Tenth step, run your tests:
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
That yields:
Test results for InstrumentationTestRunner=
Time: 0.0
OK (0 tests)
That is all. Now implement your tests, compile and install as usual. Additionally you can remove them like:
adb shell pm uninstall com.example.tests
But you will need to create instrumentation classes again to avoid the same error.
这篇关于android.util.AndroidException:INSTRUMENTATION_FAILED:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!