如何配置Android的测试目录? [英] How do I configure android tests directory?
问题描述
而Android构建的gradle我的力量来AndroidTests在SRC / androidTests。如何改变这是我选择的另一个目录?
下面是一些背景:
我从月食迁移项目。
按照构建文档,当我将它添加到我的gradle这个构建文件:
androidTest.setRoot(测试)
在Android构建的gradle做到这一点:
注:setRoot()将使整个sourceSet(及其子文件夹)到一个新的文件夹,这将移动的src / androidTest / *,以测试/ *
这是伟大的构建,使得它运行得很好。
然而,它迫使我的项目结构把内我androidTests:SRC / AndroidTest。这使得Eclipse中无法编译,因为它认为所有的测试code应该是在一个叫包androidTests.com.etc.etc.etc ...
我想设置一些属性是这样的:
androidTest
{
java.srcDirs = ['测试']
}
块引用>解决方案
androidTest.setRoot('测试')
将重置sourceSets的根,这样
- Java是在
测试/ JAVA
- 安卓资源正在
测试/ RES
- 等...
您可以配置这些虽然分开
安卓{
sourceSets {
androidTest {
java.srcDirs = ['测试']
}
}
}注:此使用
android.sourceSets
由于Android插件使用自定义sourceSetsThe Android gradle build forces my AndroidTests to be in src/androidTests. How do I change this to be another directory of my choosing?
Here is some background: I am migrating a project from eclipse.
According to the build documentation, when I add this to my gradle build file:
androidTest.setRoot('tests')
The android gradle build does this: "Note: setRoot() moves the whole sourceSet (and its sub folders) to a new folder. This moves src/androidTest/* to tests/*"
That is great for the build and makes it run just fine.
However, it forces my project structure to put my androidTests within: src/AndroidTest. This makes Eclipse unable to compile because it thinks all the test code should be in a package called androidTests.com.etc.etc.etc...
I'd like to set some property like this:
androidTest { java.srcDirs = ['tests'] }
解决方案
androidTest.setRoot('tests')
will reset the root of the sourceSets so that
- java is under
tests/java
- android res are under
tests/res
- etc...
You can configure those separately though with
android { sourceSets { androidTest { java.srcDirs = ['tests'] } } }
Note: this uses
android.sourceSets
because the Android plugin uses custom sourceSets.这篇关于如何配置Android的测试目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!