Hi I am writing unit test cases of my demo android application, so for this I am using robolectric
unit framework. When I run it gradlew test
then it gives error Could not resolve all dependencies for configuration ':app:testCompile`. Please see attached screenshot.
Below is my root build.gradle
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
My project build.grade file looks like below
apply plugin: 'android'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.xyz.robolectricapplication"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
// this sets the root test folder to src/test overriding the default src/instrumentTest
instrumentTest.setRoot('src/test')
}
}
apply plugin: 'android-test'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
}
}
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
Error Logs
Project Structure looks like below
Thanks in advance.
If you're going to grab the snapshot, you need to grab the 2.4-SNAPSHOT.
See: https://github.com/robolectric/robolectric/blob/master/pom.xml
So replace testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
with testCompile 'org.robolectric:robolectric:2.4-SNAPSHOT'
Or probably better to grab the stable 2.3 release: org.robolectric:robolectric:2.3
There is a sample gradle project here, it might be helpful: https://github.com/robolectric/deckard-gradle