Espresso 2.0 導入


Espresso 2.0 導入時に警告が出たのでメモ

開発環境

  • AndroidStudio 2.0 Preview 4

Espresso の設定(Setup Espresso)

1. build.gradle に対して以下の依存関係を記述する
build.gradle
dependencies {
    androidTestCompile 'com.android.support:support-annotations:23.0.1'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // Set this dependency if you want to use Hamcrest matching
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
}

※ com.android.support:support-annotations の警告が出ることがある
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app and test app differ.

依存関係を修正する

build.gradle
    androidTestCompile 'com.android.support:support-annotations:23.0.1'
    androidTestCompile ('com.android.support.test:runner:0.4.1') {
      exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test:rules:0.4.1') {
      exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
      exclude module: 'support-annotations'
    }
    // Set this dependency if you want to use Hamcrest matching
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'

Espresso 実行(Run Espresso Tests on a Device or Emulator)

1. build.gradle の defaultConfig に testInstrumentationRunner を指定する
build.gradle
android {
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}
2. コマンドラインから実行する

./gradlew cAT

Espresso 2.0 参考

Testing UI for a Single App