2013-01-11 14 views
16

Tôi có một ứng dụng Android đơn giản và tôi đang thử nghiệm nó bằng cách sử dụng điện thoại của mình. Vì vậy, có hai cách để làm điều đó:android.util.AndroidException: INSTRUMENTATION_FAILED:

  1. sử dụng Eclipse
  2. Sử dụng CLI

Vấn đề:

Khi tôi chạy đơn vị kiểm tra trường hợp sử dụng Eclipse, nó cài đặt ứng dụng trên điện thoại của tôi lúc chạy và chạy thử nghiệm junit và sau đó nếu tôi sử dụng lệnh trên CLI: adb -d shell am instrument -w com.abc.xyz.test/android.test.InstrumentationTestRunner, nó chạy tốt.

Tuy nhiên, nếu tôi trực tiếp chạy lệnh trên trong CLI mà không chạy các trường hợp đơn vị thử nghiệm trong Eclipse, tôi nhận được lỗi:

 
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 chứa:

android:name="android.test.InstrumentationTestRunner" 
    android:targetPackage="com.abc.xyz" 

    inside instrumentation tag 

Could bất cứ ai vui lòng giúp tôi

Trả lời

23

Tôi cho rằng bạn sẽ giải quyết nó kể từ tháng một, nhưng tôi làm việc với các công cụ dòng lệnh, tìm thấy vấn đề tương tự (thông báo lỗi là khác nhau t) và giải quyết nó như tôi giải thích trong các bước sau. Tôi làm toàn bộ quá trình từ việc tạo ra một dự án giả với thử nghiệm rỗng của nó cho đến khi chạy thử thành công.Tôi hy vọng nó có thể có ích cho ai đó:

Bước đầu tiên, tạo dự án:

android create project 
    --name MyExample 
    --target "Google Inc.:Google APIs:17" 
    --path MyExample 
    --package com.example 
    --activity MyExampleActivity 

Thứ hai bước, tạo dự án thử nghiệm:

android create test-project 
    --path MyExampleTest 
    --name MyExampleTest 
    --main ../MyExample 

Thứ ba bước, truy cập vào thư mục dự án của bạn, xây dựng nó và kiểm tra xem quá trình có kết thúc thành công hay không:

cd MyExample && ant debug 

bước thứ tư, cài đặt nó vào giả lập:

adb -s emulator-5554 install -r bin/MyExample-debug.apk 

bước Fifth, truy cập vào thư mục dự án thử nghiệm của bạn và cố gắng chạy các bài kiểm tra:

cd ../MyExampleTest && 
adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner 

Đó sản lượng:

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) 

Thứ sáu bước, liệt kê clases nhạc cụ của bạn và đảm bảo rằng dự án hiện tại của bạn là mất tích:

adb shell pm list instrumentation 

Đó năng suất máy tính của tôi:

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) 

Như bạn có thể thấy, các thiết bị đo đạc cho com.example.tests doesn không tồn tại, vì vậy chúng ta sẽ phải tạo ra nó.

Seventh bước, xây dựng cho bạn kiểm tra dự án và kiểm tra xem nó đã thành công:

ant debug 

thứ tám bước, cài đặt nó vào giả lập:

adb -s emulator-5554 install -r bin/MyExampleTest-debug.apk 

IX bước, liệt kê các lớp thiết bị đo đạc của bạn và tìm kiếm một trong các dự án của bạn:

adb shell pm list instrumentation 

Đó suất:

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) 

Nhìn vào thứ hai để kéo dài, instrumentation:com.example.tests, nó mà chúng tôi muốn.

thứ mười bước, chạy thử nghiệm của bạn:

adb shell am instrument -w com.example.tests/android.test.InstrumentationTestRunner 

Đó suất:

Test results for InstrumentationTestRunner= 
Time: 0.0 

OK (0 tests) 

Đó là tất cả. Bây giờ thực hiện các bài kiểm tra của bạn, biên dịch và cài đặt như bình thường.Ngoài ra, bạn có thể xóa chúng như:

adb shell pm uninstall com.example.tests 

Nhưng bạn sẽ cần phải tạo lại các lớp thiết bị để tránh lỗi tương tự.

+0

Cảm ơn bạn, cảm ơn bạn, cảm ơn bạn Birei! Hành động cài đặt đã giải quyết được vấn đề của tôi, vì đó là lý do tôi nhận được lỗi "Không thể tìm thấy thông tin thiết bị đo đạc" – gsaslis

+0

Tôi đã kiểm tra theo cách của bạn nhưng không hoạt động. Và một điều nữa Trong bước thứ sáu tôi có thể nhìn thấy tên của dự án của tôi trong danh sách thiết bị đo đạc nhưng khi tôi đang cố gắng chạy thử nghiệm để nó cho lỗi giống như bạn mô tả ở trên. Làm ơn giúp tôi. –

+0

bạn đã làm bất cứ điều gì tương tự với gradle? – c3rin

2

Một lời giải thích chính xác hơn/cách tiếp cận như sau:

Hãy chắc chắn rằng bạn làm

adb install -r bin/<>-debug.apk 

từ cả từ kiểm tra và thư mục ứng dụng.

Sau đó ant test sẽ hoạt động từ thư mục kiểm tra. (Tôi đoán là có sự thiếu phụ thuộc vào ứng dụng từ gói thử nghiệm - điều này gây ra lỗi).

Khác với bản hack nhỏ ở trên, phần còn lại của quy trình tôi theo dõi đến từ phần giới thiệu thử nghiệm android trên http://developer.android.com/.

1

Đảm bảo bạn gỡ cài đặt ứng dụng trước đó và cài đặt lại hoặc khởi động thử nghiệm chỉ sau khi gỡ cài đặt ứng dụng trước