The framework runs the instrumentation independently of the app, so it can
do what it wants when it wants.  And an activity is not "the app".
Activities are created all the time, you can't wait for whatever one to be
created before running the instrumentation.

http://developer.android.com/reference/android/app/Instrumentation.html

http://developer.android.com/reference/android/app/Instrumentation.html#onStart()

http://developer.android.com/reference/android/app/Instrumentation.html#runOnMainSync(java.lang.Runnable)

On Thu, Mar 5, 2009 at 7:04 AM, AndyM <andrewdm...@gmail.com> wrote:

>
> "There are APIs to allow you to run code on the main thread to access
> its objects." I'm a little confused about what APIs you are talking
> about and how they would help solve this problem. Could you clarify?
>
> To me it seems that the test runner should not be calling my tests if
> the Application is not finished initializing yet.
>
> Andy
>
>
> On Mar 4, 2:57 pm, Dianne Hackborn <hack...@android.com> wrote:
> > You are calling this while the app is running, and it hasn't finished
> > initializing.
> >
> > Generally you should be very careful about directly touching app objects
> > like this from tests, since the test is running in a separate thread.
>  There
> > are APIs to allow you to run code on the main thread to access its
> objects.
> >
> > On Wed, Mar 4, 2009 at 10:00 AM, AndyM <andrewdm...@gmail.com> wrote:
> >
> > > I have a simple androidTestCase class that has this test:
> >
> > > @MediumTest
> > > public void testFoo() {
> > >          assertNotNull(this.mContext.getApplicationContext());
> > > }
> >
> > > this fails unless I sleep first, then it passes. Whats the deal?
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > hack...@android.com
> >
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support.  All such questions should be posted on public
> > forums, where I and others can see and answer them.
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~
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