如何配置Android的测试目录? [英] How do I configure android tests directory?

查看:125
本文介绍了如何配置Android的测试目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而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插件使用自定义sourceSets

The 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆