在 Eclipse 中创建 Android 测试项目
如何在 Eclipse 中的目标项目的 /test
目录中创建 Android 测试项目?
注意:我只是根据 Stackoverflow FAQ 来回答你自己的问题,为人们做我自己的问答。
How do I create an Android Test project in Eclipse in the target project's /test
directory?
Note: I'm just doing my own Q+A for people according to the Stackoverflow FAQ on answering your own question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用 Helios 和最新版本的 Android (10.0.1)
Android 测试基本面向您推荐
将测试放在与
src
文件夹相同的项目文件夹中。有些人建议您在自己的文件夹中创建一个新的测试项目,这样它就不会打包到 apk 中。我查看了我的应用程序,我认为没有包含测试内容(但我可能是错的)。我喜欢将它放在同一目录中,因为它更方便版本控制 - 您不需要每次同步两个项目。
假设我们要为
MyAndroidApp
项目创建一个测试套件Goto File.. New.. Other.. Android...Android 测试项目
MyAndroidAppTest
MyAndroidApp
tests
目录下的 MyAndroidApp 项目中,创建该项目时,如果出现
An inside error generated while: “Refreshingworkspace”。
错误(或其他错误)忽略它。单击“确定”。- 清理
MyAndroidApp
项目即使该项目位于
/MyAndroidApp/tests
目录中,它也会在包资源管理器中显示为正常的 Eclipse 项目。清理
MyAndroidAppTest
项目。这对我有用。
编辑
如果您在 Eclipse 中上传到 SVN(通过同步
MyAndroidApp
项目,而不是MyAndroidAppTest
项目),您需要做更多的事情(我现在刚刚完成)。因此,当您更新其他工作副本时,它将拉取
/tests
目录。MyAndroidAppTest
项目不会自动显示在 Package Explorer 中。所以你需要去文件..导入...现有项目到工作区....
然后浏览到
/MyAndroidApp/tests
目录来选择根目录,然后单击“完成”。I am using Helios with the latest current version of Android (10.0.1)
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.
Assume we want to create a test suite for the
MyAndroidApp
projectGoto File.. New.. Other.. Android...Android Test Project
MyAndroidAppTest
MyAndroidApp
tests
directoryWhen it is being created, if you get a
An internal error occurred during: "Refreshing workspace".
error (or other errors) just ignore it. Click OK.-Clean the
MyAndroidApp
projectEven 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.
EDIT
If you upload to SVN in Eclipse (by syncing the
MyAndroidApp
project, not theMyAndroidAppTest
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.我在这里找到了这个问题的非常详细的解决方案。这似乎是一个ADT错误。
http://jonblack. org/2012/11/24/creating-an-android-test-project-within-a-project不过,当我在第 5 步将测试项目导入回工作区时,我得到以下内容错误消息:
我只是关闭了错误对话框,测试项目出现在我的工作区中,与我的 android 项目处于同一级别,但位置已正确设置为 MyApp/tests。
所以我写了一个测试,运行它,它起作用了。
I found here a very detailed solution to this problem. It seems to be an ADT bug.
http://jonblack.org/2012/11/24/creating-an-android-test-project-within-a-projectStill, when I import the test project back into the workspace at Step 5 I get the following error message:
I simply closed the error dialog and the test project appeared in my workspace at the same level as my android project, but the location was correctly set to MyApp/tests.
So I wrote a test, run it and it worked.