添加支持图书馆Robolectric 2.3 [英] Adding Support Library to Robolectric 2.3
问题描述
此模板,我能得到roblolectric和ES $ P灵感后$ PSSO测试,Android和摇篮的工作。关键是存储robolectric在它自己的模块。不过,我是无法支持库添加到robolectric。我该怎么办呢?
下面是robolectric模块的摇篮文件:
应用插件:Java的
// * 什么地方出了错:
//执行失败的任务:robolectric测试:测试。
//> superClassName是空的!
tasks.withType(测试){
scanForTestClasses = FALSE
包括** / * Test.class
}
依赖{
高清androidModule =项目(':应用程序)
编译androidModule
testCompile androidModule.android.applicationVariants.toList()。第一个()。javaCompile.classpath
testCompile androidModule.android.applicationVariants.toList()。第一个()。javaCompile.outputs.files
testCompile文件(androidModule.plugins.findPlugin(com.android.application)。getBootClasspath())
testCompile'的JUnit:JUnit的:4 +
testCompile('org.robolectric:robolectric:2.3'){
排除模块:支持-V13
排除模块:支持-V4
}
}
这里的顶级项目摇篮文件。正如你所看到的,我将在正确的回购的,因为应用程序模块建立,没有任何问题。
转{
版本= [
FindBugs的:2.0.3,
Checkstyle的:'5.7',
PMD:5.1.1
]
}
buildscript {
库{
mavenCentral()
}
依赖{
类路径com.android.tools.build:gradle:0.12.1+
类路径组:com.autoscout24.gradle,名称:'摇篮 - 猴插件版本:0.7+
类路径de.felixschulze.gradle:摇篮 - hockeyapp-插件:2.1+
}
}
allprojects {
库{
mavenCentral()
}
}
添加
在重读 robolectric 阅读我在github上,我注意到他们是在告诉人们将支持Android文件到本地回购。由于我使用的摇篮,这可能不是因为摇篮使用它自己的缓存,而不是本地Maven做任何事情(〜/摇篮VS ./m2)。
报价:
Robolectric需要谷歌的API为Android(特别是地图JAR)和Android支持-V4磁带库。要下载此到开发计算机上使用Android SDK工具,然后运行以下命令以将它们安装到你的本地仓库:
MVN安装:安装文件-DgroupId = com.google.android.maps \
-DartifactId =映射\
-Dversion = 18_r3 \
-Dpackaging =罐\
-Dfile =$ ANDROID_HOME /插件/插件,google_apis - 谷歌-18 /库/ maps.jar
MVN安装:安装文件-DgroupId = com.android.support \
-DartifactId =支持-V4 \
-Dversion = 19.0.1 \
-Dpackaging =罐\
-Dfile =$ ANDROID_HOME /演员/安卓/支持/ V4 / Android的支持,v4.jar
,而不是复制这些文件到本地Maven仓库,你应该能够使用Android库直接:
应用插件:Java的
库{
高清androidHome = System.getenv(ANDROID_HOME)
行家{
网址$ androidHome /演员/安卓/ m2repository /
}
}
请注意,您必须安装Android支持库和放大器;谷歌库首先通过SDK管理器。
After inspiration from this template, I was able to get roblolectric and espresso tests working with android and gradle. The key was to store robolectric in it's own module. However, I 'm unable to add the support library to robolectric. How can I do that?
Here's the gradle file of the robolectric module:
apply plugin: 'java'
// * What went wrong:
// Execution failed for task ':robolectric-tests:test'.
// > superClassName is empty!
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class"
}
dependencies {
def androidModule = project(':App')
compile androidModule
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.classpath
testCompile androidModule.android.applicationVariants.toList().first().javaCompile.outputs.files
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
testCompile 'junit:junit:4.+'
testCompile ('org.robolectric:robolectric:2.3') {
exclude module: 'support-v13'
exclude module: 'support-v4'
}
}
Here's the top level project gradle file. As you can see I'm bringing in the correct repo's because the App module builds with no problems.
ext {
versions = [
findbugs: '2.0.3',
checkstyle: '5.7',
pmd: '5.1.1'
]
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.1+'
classpath group: 'com.autoscout24.gradle', name: 'gradle-monkey-plugin', version: '0.7+'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:2.1+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Addition
While rereading the robolectric read me on github, I noticed they are telling people to move the android support files into their local repos. Since I'm using gradle, this might not do anything since gradle uses it's own caches instead of local maven (~./gradle vs ./m2).
Quote:
Robolectric requires the Google APIs for Android (specifically, the maps JAR) and Android support-v4 library. To download this onto your development machine use the Android SDK tools and then run the following to install them to your local Maven repository:
mvn install:install-file -DgroupId=com.google.android.maps \
-DartifactId=maps \
-Dversion=18_r3 \
-Dpackaging=jar \
-Dfile="$ANDROID_HOME/add-ons/addon-google_apis-google-18/libs/maps.jar"
mvn install:install-file -DgroupId=com.android.support \
-DartifactId=support-v4 \
-Dversion=19.0.1 \
-Dpackaging=jar \
-Dfile="$ANDROID_HOME/extras/android/support/v4/android-support-v4.jar"
Theoretically, instead of copying those files into the local maven repository, you should be able to use android repository directly:
apply plugin: 'java'
repositories {
def androidHome = System.getenv("ANDROID_HOME")
maven {
url "$androidHome/extras/android/m2repository/"
}
}
Note, that you have to install Android Support Repository & Google Repository first through the SDK Manager.
这篇关于添加支持图书馆Robolectric 2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!