UI中的不确定进度条出现"java.lang.RuntimeException: Could not launch intent"错误

4
是否有已知问题在使用AndroidJUnitRunner显示不确定的ProgressBar时?我在测试期间遇到了以下错误:

05-26 15:22:48.504    1003-1016/? I/TestRunner﹕ java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.HomeListActivity } 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 1432668122421 and now the last time the queue went idle was: 1432668122421. If these numbers are the same your activity might be hogging the event queue.

堆栈跟踪如下:

05-26 15:22:48.504    1003-1016/? I/TestRunner﹕ java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.HomeListActivity } 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 1432668122421 and now the last time the queue went idle was: 1432668122421. If these numbers are the same your activity might be hogging the event queue.
            at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:274)
            at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
            at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
            at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
            at com.cookbrite.step2_functional.ui.homelist.HomeListFragmentLoadingTest.testLoadingSpinner(HomeListFragmentLoadingTest.java:40)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
            at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
            at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
            at com.cookbrite.util.BaseBlackBoxTest.doRunTest(BaseBlackBoxTest.java:300)
            at com.cookbrite.util.BaseBlackBoxTest.access$000(BaseBlackBoxTest.java:44)
            at com.cookbrite.util.BaseBlackBoxTest$1.call(BaseBlackBoxTest.java:271)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:841)

由上述超时触发的线程转储显示ProgressBar似乎涉及其中:

05-26 15:22:48.135    1003-1018/? E/THREAD_STATE﹕ Thread[main,5,main]
    android.graphics.Canvas.native_drawBitmap(Native Method)
    android.graphics.Canvas.drawBitmap(Canvas.java:1160)
    android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:440)
    android.graphics.drawable.RotateDrawable.draw(RotateDrawable.java:88)
    android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:345)
    android.widget.ProgressBar.onDraw(ProgressBar.java:1052)
    android.view.View.draw(View.java:13944)
    android.view.View.draw(View.java:13825)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13823)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13947)
    android.view.View.draw(View.java:13825)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13823)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13947)
    android.widget.FrameLayout.draw(FrameLayout.java:467)
    android.view.View.draw(View.java:13825)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13823)
    android.view.ViewGroup.drawChild(ViewGroup.java:3086)
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
    android.view.View.draw(View.java:13947)
    android.widget.FrameLayout.draw(FrameLayout.java:467)
    com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2224)
    android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2482)
    android.view.ViewRootImpl.draw(ViewRootImpl.java:2395)
    android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2239)
    android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1872)
    android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
    android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
    android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    android.view.Choreographer.doCallbacks(Choreographer.java:562)
    android.view.Choreographer.doFrame(Choreographer.java:532)
    android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    android.os.Handler.handleCallback(Handler.java:730)
    android.os.Handler.dispatchMessage(Handler.java:92)
    android.os.Looper.loop(Looper.java:137)
    android.app.ActivityThread.main(ActivityThread.java:5103)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:525)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    dalvik.system.NativeStart.main(Native Method)
    Thread[Binder_2,5,main]
    dalvik.system.NativeStart.run(Native Method)
    Thread[JDWP,5,system]
    dalvik.system.NativeStart.run(Native Method)
    Thread[pool-1-thread-1,5,main]
    java.lang.Object.wait(Native Method)
    java.lang.Object.wait(Object.java:364)
    android.app.Instrumentation.startActivitySync(Instrumentation.java:403)
    android.support.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:69)
    android.support.test.runner.MonitoringInstrumentation$3.call(MonitoringInstrumentation.java:265)
    android.support.test.runner.MonitoringInstrumentation$3.call(MonitoringInstrumentation.java:262)
    java.util.concurrent.FutureTask.run(FutureTask.java:234)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    java.lang.Thread.run(Thread.java:841)
    Thread[pool-5-thread-1,5,main]
    dalvik.system.VMStack.getThreadStackTrace(Native Method)
    java.lang.Thread.getStackTrace

有人建议在测试中将所有的 ProgressBar 替换为普通的 View... 我会测试一下看看是否可行 https://blog.entwicklerbier.org/2015/05/test-your-ui-on-android-with-espresso-damn-you-progressbar/ - Yenchi
有人从Google(可能是Espresso团队的一员)表示,无法使用Espresso测试ProgressBar,因为ProgressBar会更新UI线程,从而阻止Espresso正常工作。 - Yenchi
1个回答

1

我认为你无法通过测试进度条来判断它们是否完成。

我们使用进度条只是为了展示我们在时间上的进展(例如,在30天的周期中,第7天,所以我们的进度条永远不会完成)。为了避免这个问题,我们不得不使用一个不同的API级别来进行我们的应用程序。我们似乎只在API级别为21的模拟器上遇到了这个问题。一旦我们将模拟器切换到API级别19,我们的测试就成功了。

注意:我们也尝试过在测试中使用普通视图来更改进度条,但我们决定这样做比我们喜欢的更加hacky。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接