Android多模块测试依赖项 [英] Android multi module test dependency
问题描述
使用Android Studio 3.0/android_gradle_version ='3.0.1'/gradle-4.5
假设我有两个android模块
Let's say I have two android modules
module-base
module-a
当我想从module-a中的module-base访问源时,只需将其写在我的文件中 module-a.gradle
When I want to access sources from module-base in module-a , I just need to write this in my module-a.gradle
dependencies {
implementation project(path: ':module-base')
}
但是,如果我想在模块a的测试中从模块库访问测试源怎么办? 这在上面不可行
dependencies {
testImplementation project(path: ':module-base')
}
我发现了很多建议(几岁了),内容类似于
I found lot of advices (few years old) which says something like
compileTestJava.dependsOn tasks.getByPath(':module-base:testClasses')
testCompile files(project(':module-base').sourceSets.test.output.classesDir)
或
testCompile project(':module-base).sourceSets.test.classes
但是没有人提到上述作品.从编译器的角度来看总是有问题:-/
But no one from mentioned works. There is always something wrong from the compiler point of view :-/
您能帮助我如何在两个模块之间创建Android测试代码依赖项吗?
推荐答案
实际上,我找到了解决方法.不要使用来自 module-base 的测试源,而是使用来自与测试相关的模块 module-testutils 的源,该模块的定义如下:
Actually I find just workaround for this. Don't use test sources from module-base but use sources from test related module module-testutils which is defined like this
dependencies{
testImplementation project(':module-testutils')
}
因此,您可以共享通用的测试代码,这些代码将被不可测试的apk排除在外.
Thus you can share common test code which will be excluded for non-testable apk.
这篇关于Android多模块测试依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!