Android Gradle 1.1 - 在另一个项目的测试中添加测试依赖项 [英] Android Gradle 1.1 - adding a test dependency on another project's tests
问题描述
我有两个模块:和 B 。
- A 是一个独立的模块。它的测试运行得很好。
- B 是一个依赖模块。它的测试需要在 A 的测试文件夹(在 B 中的一个测试文件在 A 中扩展一个)中的某个文件。
$ b
以下是我认为是 B 的相关部分 build.gradle
:
android {
...
sourceSets {
test.java.srcDirs + =../A/src/test/java
}
}
依赖关系{
编译项目(':A')
testCompile'junit:junit:4.10'
testCompile'org.robolectric:robolectric:2.4'
testCompile'org.mockito:mockito-核心:1.9.5'
}
虽然这在技术上适用于我所需要的 - 每当我运行 A 的单元测试时,它也会运行所有的 B 测试。我真的很喜欢这种情况。
我正在使用Android Gradle 1.1随着Android Studio 1.1),我认为这是我的一些问题。我尝试了所有我能找到的解决方案 - 不幸的是,它们中没有一个似乎适用于Android Gradle 1.1--例如: 删除 sourceSets
从 B 的 build.gradle
并添加(到 B 的依赖关系)该行
testCompile项目(':A')。sourceSets.test.output
产生构建错误无法在SourceSet容器上找到属性'test'。
我会以错误的方式回答这个问题吗?是否有一种更容易/更好的方法在模块中包含测试文件?我对Gradle / Android Studio非常陌生,所以完全有可能我错过了一个显而易见的解决方案。 解决方案
检查
gradle projects
它会列出您的所有项目模块,您可以看到是否正确配置子项目。另外运行命令:
gradle --gui
它将列出所有模块的所有任务,并且您可以始终独立运行一个模块,例如
gradle A:任务
gradle A:测试
gradle B:测试
code>
或者两者
gradle A:任务B:测试
注意:如果它是根目录,则不需要指定A项目和B,C,D子模块,但对于需要指定它的子模块。当你这样做时:
gradle --gui
您可以双击任何任务以查看它的运行方式,您可以通过命令行手动执行相同的操作。希望这有助于
I have 2 modules: A and B.
-A is a standalone module. Its tests run just fine all by itself.
-B is a dependent module. Its tests require a certain file in A's test folder (one test file in B extends one in A)
Here are what I believe to be the relevant parts of B's build.gradle
:
android {
...
sourceSets {
test.java.srcDirs += "../A/src/test/java"
}
}
dependencies {
compile project(':A')
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-core:1.9.5'
}
While this technically works for what I need it - it has the nasty side effect that whenever I run A's unit tests, they also run all of B's tests. I would really like if this was not the case.
I am using Android Gradle 1.1 (along with Android Studio 1.1), and I think this is causing me some issues. I have tried all the solutions I could find - unfortunately, none of them seem to apply for Android Gradle 1.1 - for example:
Removing the sourceSets
from B's build.gradle
and adding (to B's dependencies) the line
testCompile project(':A').sourceSets.test.output
Produces the build error Could not find property 'test' on SourceSet container.
Am I going about this the wrong way? Is there an easier/better way to include test files across modules? I'm pretty new to Gradle/Android Studio, so it's totally possible I'm missing a dead obvious solution.
Check all your modules by tree using command:
gradle projects
It will list all your project modules and you can see if you are configuring your sub projects in a right way. Also run command:
gradle --gui
It will list all the tasks for all modules, and you can always run one module independently from other e.g.
gradle A:tasks
gradle A:test
gradle B:test
OR both
gradle A:tasks B:test
Note: You do not need to specify the A if it is the root project and B,C,D sub-modules but for submodules you need to specify it. When you do:
gradle --gui
You can double click on any task to see how it runs and you can do the same manually from command line. Hope this helps
这篇关于Android Gradle 1.1 - 在另一个项目的测试中添加测试依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!