![](/img/trans.png)
[英]NoClassDefFoundError when trying to test Android app with Gradle, Robolectric and Travis CI
[英]Android gradle test with robolectric
我正在使用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測試我的應用程序?
嘗試使用插件的最新快照。
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'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.