【发布时间】:2014-06-19 20:18:40
【问题描述】:
我正在使用 gradle 构建系统来运行 Roboletric 测试,但是我遇到了这里描述的问题 Gradle Android unit tests that depend on an 'aar' 但该解决方案仅适用于构建工具版本 0.9.+ 而不是 0.11.+ 因为我找不到exploded-aar 目录。有什么想法吗?
这是部分构建文件
configurations {
testLocalCompile {
extendsFrom compile
}
}
sourceSets {
testLocal {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/res')
compileClasspath += configurations.testLocalCompile
runtimeClasspath += compileClasspath
}
}
dependencies {
testLocalCompile fileTree(dir: "$project.buildDir/intermediates/exploded-aar", include: "**/classes.jar")
}
task localTest(type: Test, dependsOn: assemble) {
testClassesDir = sourceSets.testLocal.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'intermediates', 'classes', 'debug']).join('/')
sourceSets.testLocal.compileClasspath += files(buildDir)
sourceSets.testLocal.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.testLocal.runtimeClasspath
}
check.dependsOn localTest
【问题讨论】:
-
你能分享你的 build.gradle 文件吗?另外,您是在 AS 中还是从控制台运行测试?
-
我是从控制台运行的,但是没有看到exploded-aar目录
-
应该注意的是,从第一篇关于 SO (stackoverflow.com/a/16952507/821636) 上的“localTest”单元测试hack 的帖子中,请注意在 buildDir 创建中添加了“中间体”。
标签: android unit-testing gradle robolectric