UXkQEZ7
UXkQEZ7

Reputation: 1184

Error when setting up unit testing with Gradle

I'm trying to set up Android unit testing following this tutorial: http://www.peterfriese.de/android-testing-with-robolectric/

But then I realized I don't know enough about the build system to understand what's really going on.

So I have some questions about part of my build.gradle below

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'
    }
}

and

dependencies {
    compile 'com.android.support:appcompat-v7:+'

    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.+'
}

When I do classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT', how does Gradle know where com.squareup.gradle is?

Also, right now, I get an error saying Gradle can't find the Robolectric library org.robolectric:robolectric:2.3-SNAPSHOT. Is it something I have to manually add or is the build system supposed to somehow automatically take care of it?

Upvotes: 2

Views: 807

Answers (1)

smiller
smiller

Reputation: 54

Gradle will find com.squareup.gradle from the configured repositories -- since it doesn't exist in Maven Central, it'll look in the Sonatype repo and find it there.

The Robolectric library should be available to Gradle, as visiting the snapshot repository URL manually shows it to be there. You could have an earlier version cached: mark the repository as 'changing', refresh dependencies, or simply rm -rf .gradle/caches to force Gradle to look again. See this answer for more: How can I force gradle to redownload dependencies?

Upvotes: 1

Related Questions