在 Eclipse 中创建一个 Android 测试项目 [英] Creating an Android Test project in Eclipse

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

问题描述

如何在 Eclipse 中目标项目的 /test 目录中创建一个 Android Test 项目?

How do I create an Android Test project in Eclipse in the target project's /test directory?

注意:我只是根据 Stackoverflow 常见问题解答回答您自己的问题,为人们做自己的问答.

Note: I'm just doing my own Q+A for people according to the Stackoverflow FAQ on answering your own question.

推荐答案

我使用 Helios 和最新版本的 Android (10.0.1)

I am using Helios with the latest current version of Android (10.0.1)

Android 测试基础向您推荐将测试放在与 src 文件夹相同的项目文件夹中.有些人建议你在它自己的文件夹中创建一个新的测试项目,这样它就不会被打包到 apk 中.我查看了我的 apk,我认为其中没有包含测试内容(但我可能是错的).我喜欢将它放在同一个目录中,因为它更方便版本控制 - 您不需要每次同步两个项目.

The Android Testing fundamentals recommends you place the tests in the same project folder as your src folder. Some people have recommended that you create a new test project in its own folder so it doesn't get packaged into the apk. I looked inside my apk and I don't think the test stuff was included (but I could be wrong). I like having it in the same directory as its more convenient for revision control - you don't need to sync two projects each time.

假设我们要为 MyAndroidApp 项目创建一个测试套件

Assume we want to create a test suite for the MyAndroidApp project

转到文件...新建...其他...Android...Android 测试项目

Goto File.. New.. Other.. Android...Android Test Project

  • 将测试项目名称"设置为 MyAndroidAppTest
  • 对于测试目标,选择An existing Android project".使用浏览按钮选择MyAndroidApp
  • 取消选择使用默认位置".这会将位置更改为位于 tests 目录下的 MyAndroidApp 项目
  • 点击完成
  • Set "Test Project Name" to MyAndroidAppTest
  • For Test Target, choose "An existing Android project".. Use the Browse button to select MyAndroidApp
  • Unselect "Use default location". This changes the location to be inside the MyAndroidApp project under the tests directory
  • Click Finish

当它被创建时,如果你得到一个在刷新工作区"期间发生内部错误.错误(或其他错误)只需忽略它.点击确定.

When it is being created, if you get a An internal error occurred during: "Refreshing workspace". error (or other errors) just ignore it. Click OK.

-清理MyAndroidApp 项目

即使项目位于 /MyAndroidApp/tests 目录中,它也会在包资源管理器中显示为一个普通的 Eclipse 项目.清理 MyAndroidAppTest 项目.这对我有用.

Even though the project is in the <workspace path>/MyAndroidApp/tests directory it will appear as a normal Eclipse project in the package explorer. Clean the MyAndroidAppTest project. This worked for me.

编辑

如果您在 Eclipse 中上传到 SVN(通过同步 MyAndroidApp 项目,而不是 MyAndroidAppTest 项目),您需要做更多的事情(我刚刚完成了)现在).因此,当您更新您的其他工作副本时,它会下拉/tests 目录.MyAndroidAppTest 项目不会自动显示在包资源管理器中.所以你需要去 File..Import...Existing Projects into Workspace....然后通过浏览到您的 /MyAndroidApp/tests 目录来选择根目录,然后单击完成".

If you upload to SVN in Eclipse (by syncing the MyAndroidApp project, not the MyAndroidAppTest project) you need to do a little more (I've just done it now). So when you update your other working copy it will pull down the /tests directory. The MyAndroidAppTest project does not automatically show up in the Package Explorer. So you need to go to File.. Import...Existing Projects into Workspace.... Then select the root directory by browsing to your <workspace path>/MyAndroidApp/tests directory and click Finish.

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

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