在Eclipse中创建一个Android Test项目 [英] Creating an Android Test project in Eclipse
问题描述
如何在Eclipse中的目标项目/test
目录中创建一个Android Test项目?
How do I create an Android Test project in Eclipse in the target project's /test
directory?
注意:我只是根据Stackoverflow常见问题解答(FAQ)回答自己的问题.
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
- 对于测试目标",选择现有的Android项目".使用浏览"按钮选择
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
在创建它时,如果出现An internal error occurred during: "Refreshing workspace".
错误(或其他错误),则将其忽略.点击确定.
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
项目
即使项目位于<workspace path>/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
项目),则需要做更多的事情(我现在已经完成了).
因此,当您 update 另一个工作副本时,它将下拉/tests
目录.
MyAndroidAppTest
项目不会自动显示在程序包资源管理器"中.
因此,您需要转到文件.将现有项目导入到工作区中.
然后通过浏览到您的<workspace path>/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 Test项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!