use*_*471 21 instrumentation android
我有一个简单的Android应用程序,我正在使用我的手机进行测试.所以,有两种方法可以做到这一点:
问题:
当我使用Eclipse运行单元测试用例时,它会在运行时在我的手机上安装应用程序并运行junit测试,之后如果我在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=ActivityManagerService INSTRUMENTATION_STATUS: Error=Unable to find instrumentation target package: com.abc.xyz INSTRUMENTATION_STATUS_CODE: -1
AndroidMAnifest.xml包含:
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.abc.xyz"
inside instrumentation tag
Run Code Online (Sandbox Code Playgroud)
有谁可以帮助我
Bir*_*rei 29
我想你将从1月开始解决它,但是我使用命令行工具,发现了类似的问题(错误信息不同)并解决了它,就像我在下面的步骤中解释一样.我从创建一个空项目的虚拟项目到成功的测试运行完成整个过程.我希望它对某些人有用:
第一步,创建项目:
android create project
--name MyExample
--target "Google Inc.:Google APIs:17"
--path MyExample
--package com.example
--activity MyExampleActivity
Run Code Online (Sandbox Code Playgroud)
第二步,创建测试项目:
android create test-project
--path MyExampleTest
--name MyExampleTest
--main ../MyExample
Run Code Online (Sandbox Code Playgroud)
第三步,访问项目目录,构建它并检查进程是否成功结束:
cd MyExample && ant debug
Run Code Online (Sandbox Code Playgroud)
第四步,将其安装到模拟器:
adb -s emulator-5554 install -r bin/MyExample-debug.apk
Run Code Online (Sandbox Code Playgroud)
第五步,访问您的测试项目目录并尝试运行测试:
cd ../MyExampleTest &&
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
Run Code Online (Sandbox Code Playgroud)
产量:
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)
Run Code Online (Sandbox Code Playgroud)
第六步,列出您的仪器条款并确保您当前的项目丢失:
adb shell pm list instrumentation
Run Code Online (Sandbox Code Playgroud)
在我的机器中产生:
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)
Run Code Online (Sandbox Code Playgroud)
如您所见,仪器com.example.tests
不存在,因此我们必须创建它.
第七步,构建测试项目并检查它是否成功:
ant debug
Run Code Online (Sandbox Code Playgroud)
Eigth步骤,将其安装到模拟器:
adb -s emulator-5554 install -r bin/MyExampleTest-debug.apk
Run Code Online (Sandbox Code Playgroud)
第九步,列出您的检测类并查找您的项目之一:
adb shell pm list instrumentation
Run Code Online (Sandbox Code Playgroud)
产量:
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)
Run Code Online (Sandbox Code Playgroud)
看看倒数第二个instrumentation:com.example.tests
,这是我们想要的.
第十步,运行测试:
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner
Run Code Online (Sandbox Code Playgroud)
产量:
Test results for InstrumentationTestRunner=
Time: 0.0
OK (0 tests)
Run Code Online (Sandbox Code Playgroud)
就这些.现在实现您的测试,像往常一样编译和安装.另外你可以删除它们,如:
adb shell pm uninstall com.example.tests
Run Code Online (Sandbox Code Playgroud)
但是您需要再次创建检测类以避免相同的错误.
归档时间: |
|
查看次数: |
13463 次 |
最近记录: |