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. How to troubleshoot a Stackoverflow error in android ViewRoot?

I am getting a StackOverflow error inside ViewRoot, I would appreciate
some help in troubleshooting it?
I don't understand why it causes a StackOverflow, since from the stack
trace, it is not calling something recursive.
And i don't understand why it report line 2155 as the line for the exception:

line 2155 is a if check:
    if (sendDone) {
                if (LOCAL_LOGV) Log.v(
                    "ViewRoot", "Telling window manager key is finished");
                try {
                    sWindowSession.finishKey(mWindow);
                } catch (RemoteException e) {
                }
            }


Thread [<3> main] (Suspended (exception StackOverflowError))    
        ViewRoot.deliverKeyEventToViewHierarchy(KeyEvent, boolean) line: 2155   
        ViewRoot.handleFinishedEvent(int, boolean) line: 2083   
        ViewRoot.handleMessage(Message) line: 1444      
        ViewRoot(Handler).dispatchMessage(Message) line: 99     
        Looper.loop() line: 123 
        ActivityThread.main(String[]) line: 3821        
        Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
        Method.invoke(Object, Object...) line: 521      
        ZygoteInit$MethodAndArgsCaller.run() line: 745  
        ZygoteInit.main(String[]) line: 503     
        NativeStart.main(String[]) line: not available [native method]  

Thank you.

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

2. Different APNs

Hi!

I wonder how Android deals with situations that require multiple different APNs 
to be open?

A classical example would MMS, which at least for European carriers seem to 
require a different APN than normal Internet access.

Does sending or receiving MMS break Internet connections?

Andreas
-- 
Sent from my Android phone with K-9. Please excuse my brevity.
--~--~---------~--~----~------------~-------~--~----~

3. Sleep mode in emulator

4. Will prices of mac vs. pc's encourage devs over to Android?

5. Guide for Dummies? Absolutely new ne to programming.

6. How can I see LOGV content in 'adb logcat'

7. Webview question: Is it possible to execute Javascript from Java synchronously?