Hi all, I have a test case which is trying to verify the behavior of an Async Task and am running into some problems dealing with (I think) some thread blocking situations.
I have a fairly standard ActivityInstrumentationTestCase2 which is testing a single method call on the class under test. This method call (internally) launches an AsyncTask and I am wanting the test case to assert that the task subsequently completed and triggered a callback. The callback from the AsyncTask is triggered in the onPostExecute method which will be executed on the main UI thread (which is what I want). The problem is that the JUnit test case IS effectively the main UI thread. This is a problem because I need the test to "hang around" until the async task has completed. Hence I am basically "waiting" in the Junit test for the async task to complete. This "waiting" (I have tried all approches: standard wait/notify, CountDownLatch, for loop etc) is basically blocking the JUnit thread (which is the main UI thread). The consequence is that the AsyncTask cannot complete because it is waiting on the UI thread.. which is waiting on the AsyncTask.. which means it's party night in deadlock city. Obviously if I remove the wait everything will execute ok, but my assertions will fail because the unit test will exit before the async task has completed. The strange thing is that I DON'T get a deadlock if I run the test in isolation, but I do if it's run in a suite (each test "should" be it's own complete activity lifecycle right?) Difficult one to explain.. hope this makes sense. Any clues? Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

