切换到AndroidJUnitRunner后,现有的Android UI测试停止工作

Yen*_*chi 10 android robotium android-testing

我们必须围绕我们的照相机功能的一些UI测试,之后我们从做了开关InstrumentationTestRunner,以AndroidJUnitRunner作为我们移动到咖啡/ JUnit4的一部分,我们再也不能可靠地运行我们现有的测试,由于频繁的RuntimeException当我们调用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)
Run Code Online (Sandbox Code Playgroud)

为了更好的可读性,这是RuntimeException上的错误消息作为引用:

无法在45秒内启动意图Intent {flg = 0x14000000 cmp = com.cookbrite.dev/com.cookbrite.ui.ReceiptCaptureActivity(has extras)}.也许主线程在合理的时间内没有闲置?可能会有一个动画或不断重新绘制屏幕的东西.或者活动是在创建网络呼叫?请参阅threaddump日志.在您的活动启动请求为1434471981236之前,事件队列最后一次空闲以供您参考,现在队列空闲的最后时间是:1434471981236.如果这些数字相同,您的活动可能会占用事件队列.

我们现有的测试使用Robotium.尝试使用Espresso编写相同的测试产生了类似的错误,这可能是由于相机预览不断更新UI.但是,即使设置了预览INVISIBLE,我们仍然会遇到Espresso问题.

关于如何解决这个问题的任何想法/指针(除了回到InstrumentationTestRunner)?

Yen*_*chi 0

最后,我们更改了 UI 以延迟相机预览启动,这样就MonitoringInstrumentation不会因所有 UI 更新而感到不安。此外,SurfaceView一旦TextureView连接相机,即使处于INVISIBLE或GONE状态,也会立即发布 UI 更新。MonitoringInstrumentation这就是我们案例中放弃的原因。

如果您的测试以不断的 UI 更新开始,您可能需要考虑暂停该操作,直到startActivitySync()完成并从 中获得非空结果getActivity()。