gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:02:17 27 4
gpt4 key购买 nike

是否可以在自己的模块中设置 robolectric 并将其作为依赖项添加到我的项目中?我可以将它添加到我的项目模块中,但如果它在它自己的模块中,我更喜欢它。我创建了一个 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"
}

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

最佳答案

是的,它可以使用不同的插件。 robolectric 支持的插件不支持这个。

插件可以在这里找到 https://github.com/novoda/gradle-android-test-plugin
可以在此处找到一个现成的示例 https://github.com/nenick/android-gradle-template

关于android - 我可以在自己的模块中设置 Robolectric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24428027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com