14

Once upon a time, I avoided Eclipse for Android development. And life was good.

Along the way, I adopted a convention originally supported by the Android command-line build tools, of having a tests/ subdirectory containing the test code (e.g., MyProject/ being the home of the app, MyProject/tests/ being the home of the test suite). Android does an excellent job of allowing test code to reside in a separate-but-related project, and having it as a subdirectory kept the tests logically co-located with the project proper.

I am now switching to Eclipse, as I need to support it better for my subscribers. The only way for me to do a quality job of supporting it is to use it daily. And, since I have a quad-core with 4GB of RAM, Eclipse actually starts up in less than a minute. :-)

However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).

So, my questions are:

  1. Am I correct in this assessment, and if I'm wrong, are there any particular steps I should take to ensure that Eclipse is happy? I find that Eclipse can sometimes get a wee bit cranky...

  2. How are Android developers organizing test projects relative to the project being tested? Peer directories (e.g., MyProject/ for the app, MyProjectTests/ for the tests)? Peer subdirectories under some targeted common top (e.g., MyProject/app/ for the Android app, MyProject/tests/ for the test suite?)? Something else?

BTW, I'm running Eclipse 3.5.2, if that matters.

Thanks!

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491

2 Answers2

6

I've been creating test projects with Eclipse 3.6.2 inside my main project just like you describe for command line tools (MyProject and MyProject/test are Android projects that both contain a src folder). You can create this test project using the New Android Test Project by deselecting "Default Location" and setting the path.

None of my projects are very large, but the only problem I've had so far is that you cannot use the MyProject/test folder under the MyProject project. To be able to right click and run as a test case, you have to access files directly from the MyProjectTest project. To prevent you from having problems, you can add a Resource Filter to hide the test folder in Project Properties > Resource > Resource Filters.

However, preliminary research suggests that Eclipse does not support sub-projects (i.e., one Eclipse project having another Eclipse project in a subdirectory).

What problems have you seen?

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • "What problems have you seen?" -- I imported an Android project, saw that it did not recognize the test project, then elected to do some research online. Every post I came up with, including bug reports on eclipse.org, indicated that projects-within-projects aren't supported. I figured I'd start soliciting Android-specific advice at that point. Later today, I'll experiment with your structure -- the resource filters in particular will be useful to minimize confusion. I'll swing back and accept your answer if I can get this working. Many thanks! – CommonsWare Jul 05 '11 at 10:39
  • 1
    Couple of follow-up notes here. The Resource Filters option might be new to 3.6; I'm on 3.5.2 and do not see it. Also, it looks like you can't create test projects from existing source the way you can regular Android projects, which is mildly annoying. I wound up renaming my `tests/` directory, creating a new test project there, and moving the test case source code back into position. But, that at least appears to be working. Thanks! – CommonsWare Jul 05 '11 at 22:37
2
  1. Depends on your toolset:
    ADT >= v12 currently has flaky support for "a project within a project":
    Creating an Android Test project in Eclipse

  2. I have tried separate testproject, and separate test directory, but afaik "a project within a project" approach seems to be the way of the future.
    This is becuase AndroidManifest.xml merging into the test project AndroidManifest.xml, is in the pipeline for the next ADT releases.

Community
  • 1
  • 1
user77115
  • 5,517
  • 6
  • 37
  • 40