在 Android Studio 中创建单独的测试模块/项目 [英] Create separate test module/project in Android Studio

查看:25
本文介绍了在 Android Studio 中创建单独的测试模块/项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Android Studio 0.8.14 版.目前,在创建一个新的Android项目后,默认情况下,测试源代码文件夹androidTest位于app模块的src文件夹中,在与 main(包含应用程序源代码)相同的级别.但是,如果出于任何特定原因,我想将测试代码移动到我项目中的一个单独模块中,或者甚至进一步移动到我用于应用程序源代码的项目之外的单独项目中,我可以这样做吗?

I'm using Android Studio version 0.8.14. Currently, after creating a new Android project, by default the test source code folder androidTest is located inside the src folder of the app module, at the same level as main (which contains application source code). But if, for any particular reason, I want to move the test code into a separate module in my project, or even further, into a separate project other than the project I'm using for application source code, can I do this?

为了让您更容易理解我的要求,最好附上一张图片".Android Studio 创建的当前默认新项目结构如下所示:

To make it easier for you to understand what I'm asking, a 'picture' would be better. The current default new project structure which Android Studio create is something looks like this:

My Project
    |___my app module
        |___src
            |___androidTest
            |___main

现在我想要这样的东西:

Now I want something looks like this:

My Project
    |___my app module
    |    |___src
    |        |___main
    |___my test module

或者这个:

My App Project
|    |___my app module
|
My Test Project (some how linked to My App Project)

我怎样才能得到这个?任何帮助将不胜感激.

How can I get this? Any help would be appreciated.

推荐答案

如果我明白你在问什么,你可能缺少的一些信息是添加如下内容:

If I understand what you are asking, the bit of information that you might be missing is to add something like:

include ':my app module', ':my test module'

到您的 settings.gradle 文件.我使用这种技术将我的连接"测试与纯单元测试分开.您可能有兴趣查看我由流行的 decard-gradle 项目制作的分叉,该项目正是这样做的:https://github.com/jdonmoyer/deckard-gradle

to your settings.gradle file. I use this technique to separate out my 'connected' tests from pure unit tests. You might be interested in checking out a fork that I made of the popular deckard-gradle project that does exactly this: https://github.com/jdonmoyer/deckard-gradle

这篇关于在 Android Studio 中创建单独的测试模块/项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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