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

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

问题描述

我正在使用Android Studio版本0.8.14.当前,在创建新的Android项目之后,默认情况下,测试源代码文件夹androidTest位于app模块的src文件夹内,与main位于同一级别(包含应用程序源代码). 但是,如果出于某种特殊原因,我想将测试代码移到项目中的单独模块中,甚至移到我用于应用程序源代码的项目以外的其他项目中,我可以这样做吗?/p>

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

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

现在我想要的东西看起来像这样:

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)

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

解决方案

如果我了解您的要求,那么您可能会缺少的一些信息就是添加以下内容:

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

到您的settings.gradle文件.我使用这种技术将连接"测试与纯单元测试分开.您可能有兴趣检查一下我是由一个受欢迎的deckard-gradle项目制成的货叉,该货叉确实做到了: https ://github.com/jdonmoyer/deckard-gradle

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?

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

or this:

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'

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天全站免登陆