1

嗨,我正在编写我的演示 android 应用程序的单元测试用例,因此我正在使用robolectric单元框架。当我运行它时,gradlew test它会给出错误无法解析配置“:app:testCompile”的所有依赖项。请参阅随附的屏幕截图。

下面是我的根 build.gradle

构建.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()
    }
}

我的项目 build.grade 文件如下所示

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

错误日志

在此处输入图像描述

项目结构如下所示

在此处输入图像描述

提前致谢。

4

1 回答 1

0

如果要抓取快照,则需要抓取 2.4-SNAPSHOT。

见:https ://github.com/robolectric/robolectric/blob/master/pom.xml

所以替换 testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'testCompile 'org.robolectric:robolectric:2.4-SNAPSHOT'

或者可能更好地获取稳定的 2.3 版本:org.robolectric:robolectric:2.3

这里有一个示例 gradle 项目,它可能会有所帮助:https ://github.com/robolectric/deckard-gradle

于 2014-10-02T13:02:43.860 回答