我正在使用AndroidStudio并使用gradle构建。
我想用Robolectirc测试我的应用,所以我在build.gradle中添加以下内容
buildscript的依赖项部分:
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.+'
应用android-test插件:
apply plugin: 'android-test'
使用testCompile配置添加仅测试依赖项:
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.1.+'
testCompile 'com.squareup:fest-android:1.0.+'
这些来自https://github.com/JakeWharton/gradle-android-test-plugin
所以我添加了这些东西,我得到gradle.build如下。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.+'
}
}
apply plugin: 'android'
apply plugin: 'android-test'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
signingConfigs {
freeConfing {
storeFile file("../../../workspace_android/keystore/pm.keystore");
storePassword "password"
keyAlias "key"
keyPassword "password"
}
paidConfing {
storeFile file("../../../workspace_android/keystore/pm.keystore");
storePassword "password"
keyAlias "key"
keyPassword "password"
}
}
productFlavors {
paid {
packageName "com.my.app"
buildConfig "public final static boolean isFullVersion = true;"
versionCode 2
versionName "1.0.0"
signingConfig signingConfigs.paidConfing
}
free {
packageName "com.my.app"
buildConfig "public final static boolean isFullVersion = false;"
versionCode 2
versionName "1.0.0"
signingConfig signingConfigs.freeConfing
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.1.+'
testCompile 'com.squareup:fest-android:1.0.+'
}
我想测试我的应用程序,我输入了类似
的终端 gradle test
但是,我得到了
Could not determine the dependencies of task ':MyApp:testFreeDebug'.
产品风味名称已更改testFreeDebug
且gradle tasks
也无效...
在我没有添加测试内容之前,它很好用。
如何使用robolectric测试我的应用程序?
答案 0 :(得分:5)
尝试使用插件的最新快照。
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}