LoginSignup
8
8

More than 5 years have passed since last update.

Android で JUnit4 を使う方法 (Espressoなし)

Last updated at Posted at 2015-03-17

はじめに

Android で JUnit4 を使う方法は 続・AndroidでJUnit4を使う方法 に紹介されていますが、Espressoなしで使う方法が書かれていなかったので、やり方を記載します。

といっても build.gradle の設定が若干違うだけです。テストクラスの書き方は同じです。

build.gradle の設定

dependency と android.defaultConfig に以下のように設定を追加します。

build.gradle
dependency {
    ...
    // 以下2行追加
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
}

android {
    ...
    defaultConfig {
        ...
        // 以下1行追加
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
}

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8