繁体   English   中英

我可以在自己的模块中设置Robolectric吗

[英]Can i setup Robolectric in its own module

是否可以在自己的模块中设置robolectric并将其作为依赖项添加到我的项目中? 我可以将其添加到我的项目模块中,但是如果它在自己的模块中,则可以使用id。 Ive创建了一个javaLibrary模块,并将以下代码添加到了gradle构建脚本中

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
dependencies {
    //Prior to AS 0.5.9: classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+'
    classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.0'

    //previous plugin >> classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT'
    }
}

allprojects {
repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
}

apply plugin: 'android'
apply plugin: 'android-test' //previously >> apply plugin: 'robolectric'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.irishtimes.newsapp.tests"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets {
    androidTest.setRoot('src/tests') //note that this is androidTest instead of instrumentTest
    }
}


dependencies {
    androidTestCompile 'junit:junit:4.10'
    //include the stable robolectric 2.3 library
    androidTestCompile 'org.robolectric:robolectric:2.3'
    androidTestCompile 'com.squareup:fest-android:1.0.+'
}

//only include files that are suffixed with Test.class and set the max heap size
androidTest {
    include '**/*Test.class'
    maxHeapSize = "2048m"
}

Ive还在src / tests / java中添加了一个空白清单文件和一个虚拟测试。 在我以前的设置中,当我运行./gradlew测试时,我的测试将运行并且id得到反馈。 现在,当我运行相同的命令时,我的构建脚本将运行,但它根本无法接受我的测试。 如果有人对教程或建议或快速解决方案有任何参考,那就太好了。 谢谢!

是的,使用其他插件是可能的。 robolectric支持的插件不支持此功能。

可以在这里找到插件https://github.com/novoda/gradle-android-test-plugin一个可以立即使用的示例可以在这里https://github.com/nenick/android-gradle-template

如果您想从一个单独的文件夹(但不一定是一个单独的模块)运行测试,那么Android Studio单元测试插件以及此gradle插件可以让我取得一些成功。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM