OK, so you now have two projects in Eclipse, MyProject and
MyProjectTest.

MyProject's files are in <someworkspace>/MyProject. From now on, I'll
just abbreviate this /MyProject.

MyProjectTest's *files* are in /MyProject/tests. For this reason, you
have two projects, but one of them has its files completely within the
other one.

*Just as a note*, you will see that the Project Explorer node for
MyProject has sub-nodes for the MyProject files and *also* for the
MyProjectTest files.

You should run the tests from MyProjectTest, by selecting the
MyProjectTest node in Project Explorer, and then right-clicking and
selecting Run As > Android JUnit Test.

To say this another way, on your disk you have the following directory
structure

/MyProject/
   src/
   gen/
   res/
   tests/
      src/
      gen/
      res/

*In Eclipse*, the project MyProject is associated with the directory /
MyProject/. The project MyProjectTest is associated with the
directory /MyProject/tests.

The point of having tests/ inside MyProject is to keep the tests near
the source code they're testing. That way, if you have to move, share,
backup, restore, or whatever your source files, you're much less
likely to forget the tests.

You still need to have two *projects* at the same level in Eclipse
because you use different tools to run them. You can't run a test
project as an Android application, and you can't run an Android
application as a test project. I think that you may want to click some
button to run one or more tests that you've pre-associated with an
application project. That is, you'd like a single button associated
with your application that runs the tests for the application. It's
certainly possible to do this in Ant, by setting up the proper target.
It's an interesting idea.

A. Elk.


On Dec 8, 2:45 pm, Etienne Lawlor <lawloretie...@gmail.com> wrote:
> I have already created the test project MyProjectTest which shows up at the
> same level of MyProject.  Also when i created that test project there is a
> subdirectory /tests which is in the root directory of MyProject.  I dont get
> what you mean when you say:
>
> >You need to create an ecliose project for the tests folder and run that one
>
> as an andrdoid instrumentation.
>
> Could you help clarify this, because i think i have already done this.
>  Thanks.
>
>
>
>
>
>
>
> On Wed, Dec 8, 2010 at 2:16 PM, Xavier Ducrohet <x...@android.com> wrote:
> > You need to create an ecliose project for the tests folder and run that one
> > as an andrdoid instrumentation.
> > On Dec 8, 2010 11:51 AM, "Etienne Lawlor" <lawloretie...@gmail.com> wrote:
> > > Yes i am using Eclipse. I did all of your steps up to the point where you
> > > said
>
> > >>So, if you used /home/etienne/workspace/MyProject as the location for
> > >>your app project, use the location /home/etienne/workspace/MyProject/
> > >>tests as the location for your test project.
>
> > > When i click finish, then i get an error that says:
>
> > > 'Refreshing workspace has encountered a problem'
> > > An internal error occurred during: 'Refreshing workspace'
> > > Element not found: /MyProject/tests.
>
> > > It shows a red x icon on the MyProjectTest project but if i clean the
> > > project
> > > then this disappears.
>
> > > I do see that now there are two projects: MyProject and MyProjectTest.
> > > In the root directory of MyProject there is a subdirectory /tests.
> > > In the /tests directory i do see that AndroidManifest.xml file that has
> > an
> > > instrumentation element which seems to be set up properly.
>
> > > I don't understand this part of what you said:
>
> > >>*Even though the tests directory appears in MyProject*, do *not* use
> > >>it to create or run tests. This is a weird artifact of Eclipse; you
> > >>can create a project as a subdirectory of another project, but you'll
> > >>see the second project *inside* the first one.
>
> > > So what is the point of the /tests subdirectory if there is a test
> > project
> > > at
> > > the same level as the app project and you can only run that seperate
> > project
> > > as an Android JUnit test?
>
> > > Also when you say:
>
> > >>If you look in the sample apps, all of them (except one) use the
> > >>"best practice" that is documented.
>
> > > I guess the "best practice" means that /tests is a subdirectory of
> > > /MyProject.
> > > I've seen an example of this in the API Demos. However i don't see how
> > you
> > > can run MyProject as an Android JUnit test, even though there is an
> > > AndroidManifest.xml with an instrumentation element with a testrunner in
> > the
> > > /tests
> > > subdirectory.
>
> > > Thanks for all your help Joe. This is the first time ive been able to get
> > > some kind of response
> > > to my question in this googlegroup.
>
> > > On Wed, Dec 8, 2010 at 10:59 AM, A. Elk <lancaster.dambust...@gmail.com
> > >wrote:
>
> > >> You have not said how you created the test project.
>
> > >> Reading between the lines, I am guessing that you did it in Eclipse.
>
> > >> To do it correctly, you should first use the New Android Project
> > >> wizard in Eclipse to create your app project. In the Contents panel,
> > >> in the Location textbox, you can accept the default location. *Write
> > >> down the location path*
>
> > >> The last step of the wizard asks you if you want to create a test
> > >> project. Say yes. Give it a name that is *different* from the app
> > >> project. I usually use <appproject>Test. In the Location textbox, do
> > >> *not* use the default location. Instead, create a tests/ directory
> > >> under the location you used for your app.
>
> > >> So, if you used /home/etienne/workspace/MyProject as the location for
> > >> your app project, use the location /home/etienne/workspace/MyProject/
> > >> tests as the location for your test project.
>
> > >> This should give you two projects in the Project Explorer, MyProject
> > >> and MyProjectTest. You can confirm that your test project is set up
> > >> correctly. Look in MyProjectTest, and open AndroidManifest.xml. Look
> > >> in the far right-hand tab under the main editor for the
> > >> androidmanifest.xml tab. This shows you the raw XML. You should see an
> > >> <instrumentation> element.
>
> > >> Run MyProjectTest as an Android JUnit application.
>
> > >> You should run *MyProjectTest* as an Android JUnit Test.
>
> > >> *Even though the tests directory appears in MyProject*, do *not* use
> > >> it to create or run tests. This is a weird artifact of Eclipse; you
> > >> can create a project as a subdirectory of another project, but you'll
> > >> see the second project *inside* the first one.
>
> > >> Also, the Android Create Test Project wizard default behavior does
> > >> *not* use the "best practice". Instead, it defaults to creating a
> > >> separate test directory at the same level as the app directory. This
> > >> isn't a good idea, IMHO. It makes it hard to maintain the relationship
> > >> between your app and its tests. If you look in the sample apps, all of
> > >> them (except one) use the "best practice" that is documented.
>
> > >> Joe
>
> > >> On Dec 7, 5:58 pm, Etienne <lawloretie...@gmail.com> wrote:
> > >> > On the developer.android.com website there is a guide to testing
> > >> > android that says:
>
> > >> > You can create a test project anywhere in your file system, but the
> > >> > best approach is to add the test project so that its root directory
> > >> > tests/ is at the same level as the src/ directory of the main
> > >> > application's project. This helps you find the tests associated with
> > >> > an application. For example, if your application project's root
> > >> > directory is MyProject, then you should use the following directory
> > >> > structure:
>
> > >> > MyProject/
> > >> > AndroidManifest.xml
> > >> > res/
> > >> > ... (resources for main application)
> > >> > src/
> > >> > ... (source code for main application) ...
> > >> > tests/
> > >> > AndroidManifest.xml
> > >> > res/
> > >> > ... (resources for tests)
> > >> > src/
> > >> > ... (source code for tests)
>
> > >> > The link to the website is:
> > >>http://developer.android.com/guide/topics/testing/testing_android.html
>
> > >> > So i took this approach and then tried to Run MyProject as an Android
> > >> > JUnit Test. However when i do this the error message i get says:
>
> > >> > "An instrumentation test runner is not specified!"
>
> > >> > This would make sense if i didn't have the test manifest file
> > >> > AndroidManifest.xml in the tests/ directory but i do have the file
> > >> > there. What could be the issue? I have been able to create a test
> > >> > project that is separate from the main project and run the test
> > >> > project as an Android JUnit Test, but i don't get how to "add the test
> > >> > project so that its root directory tests/ is at the same level as the
> > >> > src/ directory of the main application's project". Does anyone know
> > >> > whats going on here, or has anyone been successful in getting this to
> > >> > work? Thanks for any help.
>
> > >> --
> > >> You received this message because you are subscribed to the Google
> > >> Groups "Android Developers" group.
> > >> To post to this group, send email to
> > android-developers@googlegroups.com
> > >> To unsubscribe from this group, send email to
> > >> android-developers+unsubscr...@googlegroups.com<android-developers%2Bunsubs
> > >>  cr...@googlegroups.com>
> > <android-developers%2bunsubscr...@googlegroups.com<android-developers%252Bu 
> > nsubscr...@googlegroups.com>
>
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com<android-developers%2Bunsubs
> > >  cr...@googlegroups.com>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com<android-developers%2Bunsubs 
> > cr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to