Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android/Espresso Intent error on running tests

I am getting the error below in Jenkins and on certain teammates computers when running Espresso tests. I have searched this error and see a lot of it has to do with either timing out or some animation. All devices have Animations off.

For example: I was getting this issue last week and I uninstalled all of Android Studio, removed the code, and then reinstalled it all. It did not work. I also upgraded Java and the JDK. After that i was still getting this issue. Then one day it just worked. I have no idea why.

Now my coworkers are getting this issue. One has this issue when ran against one device (5.1) and not another (6.0). A different coworker is having the opposite problem.

So my question is - what can I check? What would be the steps to take? We have compared notes on devices - all IDEs match up with version number and build tools and so on. I am running out of ideas.

Thanks!

java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.COMPANY.espresso/com.COMPANY.activity.LauncherActivity } 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 1469050322683 and now the last time the queue went idle was: 1469050322683. If these numbers are the same your activity might be hogging the event queue.
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:360)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:219)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:268)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1862)
like image 289
Skycamefalling Avatar asked Nov 09 '22 11:11

Skycamefalling


1 Answers

My first guess is, that the ProgressBar blocks Espresso and that the content view of your Activity contains a indeterminate ProgressBar, that is always visible or becomes visible before onResume returns. The animation keeps the App busy and Espresso waits until it times out. This would create exactly the error you posted.

Because your tests are working sometimes, I assume that the visibility of the ProgressBar depends on a background task. If the progress bar is hidden (or removed from the view hierarchy) before Espresso times out, the tests run.

The second guess is, that you are using AsyncTasks for the background jobs. If you start long running AsyncTasks before onResume returns this would also create the error you posted.

To check if the ProgressBar is the reason you could remove it completely, or replace its indeterminate drawable with an static one (i.e. a ColorDrawable).

like image 130
thaussma Avatar answered Nov 15 '22 04:11

thaussma