We have a few UI tests around our camera functionality, and after we made the switch from InstrumentationTestRunner
to AndroidJUnitRunner
as part of our move to Espresso/JUnit4, we can no longer run our existing tests reliably due to frequent RuntimeException when we call getActivity()
:
java.lang.RuntimeException: Could not launch intent Intent { flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.ReceiptCaptureActivity (has extras) } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1434471981236 and now the last time the queue went idle was: 1434471981236. If these numbers are the same your activity might be hogging the event queue.
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:315)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:106)
at com.cookbrite.step2_functional.ui.receipt.ReceiptCaptureTest.getActivity(ReceiptCaptureTest.java:43)
For better readibility, this is the error message on the RuntimeException as a quote:
Could not launch intent Intent { flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.ReceiptCaptureActivity (has extras) } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1434471981236 and now the last time the queue went idle was: 1434471981236. If these numbers are the same your activity might be hogging the event queue.
Our existing tests use Robotium. An attempt to write the same test using Espresso yielded similar error, which is probably due to camera preview constantly updating the UI. However, even with preview set to INVISIBLE
, we still run into this issue with Espresso.
Any ideas/pointers on how to fix this (other than go back to InstrumentationTestRunner
)?
getActivity()
timeout bug was fixed in 0.3. Hopefully your case was also addressed. – Contributory