Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

unit testing - Creating an Android Test project in Eclipse

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 project

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

  • 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.

-Clean the MyAndroidApp project

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.

EDIT

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...