android studioとrobolectricの設定
2574 ワード
robolectricは、そのままだとandroid studioでうまく動かないので、プラグインAndroid Studio Unit Test
を利用する。
設定
1.プロジェクトディレクトリ直下のbuild.gradleに以下を追加
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.2'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
}
}
allprojects {
repositories {
jcenter()
}
}
2.appディレクトリ下のbuild.gradleに以下を追加
apply plugin: 'com.android.application'
android {...}
apply plugin: 'android-unit-test'
dependencies {
// testing
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'junit:junit:4.+'
}
3.プラグインの追加
android studio -> preference -> plugins -> browse repositoryを開き、'Android Studio Unit Test'を検索しインストール
4.androidTestディレクトリの名前をtestに変更
5.appディレクトリ配下の、build.gradleファイルにafterEvaluateを追加
apply plugin: 'com.android.application'
android {...}
apply plugin: 'android-unit-test'
afterEvaluate {
tasks.findByName("assembleDebug").dependsOn("testDebugClasses")
}
dependencies {...}
テストの実行
-
テストの実行の設定をする。
Robolectricに、manifestファイルの場所を教える。
@RunWith(RobolectricTestRunner.class)
@Config(manifest="./src/main/AndroidManifest.xml")
public class MyActivityTest {
...
}
Author And Source
この問題について(android studioとrobolectricの設定), 我々は、より多くの情報をここで見つけました https://qiita.com/shrft/items/a49ffec4443a46e23d5a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .