Robolectric with Gradle: Resources not found

后端 未结 2 1408
忘掉有多难
忘掉有多难 2020-12-07 10:13

I\'m trying to run my Robolectric tests together with the new Gradle Android build system, but I\'m stuck at accessing the resources of my main project.

I split the

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 10:36

    Update: Jake Wharton just announced the gradle-android-test-plugin. You can find it at https://github.com/square/gradle-android-test-plugin

    It seems to be pretty streamlined, especially if you plan to use robolectric.


    Old Answer Below

    The robolectric-plugin looks promising.

    The sample build.gradle file they provide is :

    buildscript {
        repositories {
            mavenCentral()
            maven {
                url "https://oss.sonatype.org/content/repositories/snapshots"
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
            classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT'
        }
    }
    
    apply plugin: 'android'
    apply plugin: 'robolectric'
    
    repositories {
        mavenCentral()
        mavenLocal()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots"
        }
    }
    
    dependencies {
        //compile files('libs/android-support-v4.jar')
    
        // had to deploy to sonatype to get AAR to work
        compile 'com.novoda:actionbarsherlock:4.3.2-SNAPSHOT'
    
        robolectricCompile 'org.robolectric:robolectric:2.0'
        robolectricCompile group: 'junit', name: 'junit', version: '4.+'
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "17.0.0"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 17
        }
    }
    

    It doesn't seem to work with the Android Gradle plugin version 0.5 but maybe it will soon.

提交回复
热议问题