[英]Configuring Gradle + Robolectric
I'm starting to use gradle and robolectric. 我开始使用gradle和robolectric。
I'm following this example: 我正在关注以下示例:
http://www.peterfriese.de/android-testing-with-robolectric/ http://www.peterfriese.de/android-testing-with-robolectric/
However, he complains the lack of JUnit and Roboeletric classes. 但是,他抱怨缺少JUnit和Roboeletric类。
Below is my file build.gradle and some prints 下面是我的文件build.gradle和一些打印
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}
apply plugin: 'android'
apply plugin: 'android-test'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
instrumentTest.setRoot('src/test')
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.1.0'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'com.squareup:fest-android:1.0.+'
}
You have to add build type debug
(correctly to say you need to have different from release build type). 您必须添加构建类型debug
(正确地说,您需要与发布构建类型不同)。 It is square test plugin requirement as well as Robolectric test plugin ( https://github.com/robolectric/robolectric-gradle-plugin/blob/master/src/main/groovy/org/robolectric/gradle/RobolectricPlugin.groovy#L42 ). 它是方形测试插件要求以及Robolectric测试插件( https://github.com/robolectric/robolectric-gradle-plugin/blob/master/src/main/groovy/org/robolectric/gradle/RobolectricPlugin.groovy#L42 )。
Modify your build.gradle
to next: 将您的build.gradle
修改为下一个:
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
}
}
And don't forget to switch Android studio to debug variant: 并且不要忘了切换Android Studio来调试变体:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.