設定 Espresso
在 Android 應用模組的 build.gradle
檔案中新增下一個依賴項:
dependencies {
// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
// Espresso core
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
//UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.2.2'
}
在 build.gradle
檔案中為 testInstrumentationRunner
引數指定 AndroidJUnitRunner
。
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
此外,新增此依賴項以提供意圖模擬支援
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
並新增此一個用於 webview 測試支援
// Espresso-web for WebView support
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'