2016-03-28 14 views
13

Tôi đang cố gắng để nhập khẩuAndroid Espresso thử nghiệm 'Không thể giải quyết biểu tượng 'InstrumentationRegistry''

import android.support.test.InstrumentationRegistry; 

tôi tập build.gradle

androidTestCompile 'com.android.support.test:testing-support-lib:0.1' 
androidTestCompile 'com.android.support.test:runner:0.2' 
androidTestCompile 'com.android.support.test:rules:0.2' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 

trong cấu hình mặc định:

defaultConfig { 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

Có thư viện nào tôi đang thiếu ở đây không? Tôi đang cố gắng nhập InstrumentationRegistry nhưng nó không nhận ra nó!

+0

vui lòng truy cập http://stackoverflow.com/questions/30373074/sources-of-testing-support-library-in-android-studio. Hi vọng điêu nay co ich . –

+1

@IntelliJAmiya yeah Tôi đã cố gắng mà không hoạt động. – Adz

+0

bạn có thấy: http://stackoverflow.com/questions/29869832/android-studio-project-setup-for-espresso-tests – piotrek1543

Trả lời

17

Kiểm tra loại thử nghiệm nào bạn sử dụng.

InstrumentationRegistry sử dụng cho instrumented kiểm tra sử dụng giả lập hoặc thiết bị và chúng được đặt trong src/androidTest và sử dụng cấu hình androidTestCompile.
Nếu bạn sử dụng kiểm tra đơn vị địa phương cho JVM từ thư mục src/kiểm tra bạn nên sử dụng cấu hình testCompile

testCompile 'com.android.support.test:runner:0.2' 

Sau đó bạn có thể nhập InstrumentationRegistry, nhưng bạn sẽ nhận được các lỗi khác tại thời gian chạy.

+0

Đồng ý, câu trả lời tuyệt vời! Xin Chúa ban phước cho bạn!) Tôi đã thay đổi androidTestCompile thành testCompile và InstrumentationRegistry được giải quyết, –

0

thử

biên dịch 'com.android.support.test: Á hậu: 0.2'

thay vì

testCompile 'com.android.support.test: Á hậu: 0.2'

Các vấn đề liên quan