getApplicationContext returns null in test case (unless you sleep first)

by AndyM » Thu, 05 Mar 2009 02:20:38 GMT


Sponsored Links
 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?


--~--~---------~--~----~------------~-------~--~----~



getApplicationContext returns null in test case (unless you sleep first)

by AndyM » Thu, 05 Mar 2009 23:04:57 GMT


 "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





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Specifying relative positions in Layout?

Hi All,

I need to implement a screen containing a list of blocks one below the
other. Each block will contain mutiple superimpose elements (Images,
text) for which the relative position needs to be specified with
respect to the top left corner of the block.

For creating the list of blocks  i have used listview. For each  block
i tried to use relative layout.This works ok when the phone is in
landscape mode and absolute position is specified relative to left
edge of the phone. But when the phone is put in the portrait mode the
layout gets distorted.

1) What layout can be used for this scenario?

2) Can relative positions be specified in terms of percentage of
screen width/height instead of pixels?
--~--~---------~--~----~------------~-------~--~----~

2. Can we put inner layout in center of the screen.

Hi All,

I want to put inner layout in center of the screen. Please help me here.

-- 
Regards,
Jitendra Bachhav.

--~--~---------~--~----~------------~-------~--~----~

3. Android 1.6 Maps Application

4. Image scaling by BitmapFactory.decodeResource()

5. How to put TextView in same position in landscape and portrait mode in Android

6. App upgrade (with zipalign) causes force closes/disappearing of app icon

7. AppWidgetProvider.onUpdate() -- setOnClickPendingIntent