1

与无限循环的视图事件相关的错误是这个问题的主题。这样的循环不会 throw StackOverflowError,因为执行得非常频繁,但不是递归的。该代码错误的一个示例可以在自定义视图invalidate()内调用。onDraw

默认情况下, AndroidJUnit4在启动测试活动后等待应用空闲,然后执行验证。但是在无限生命周期循环的情况下,将无法实现空闲并且测试将失败并出现错误java.lang.RuntimeException: Could not launch intent Intent within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? 这样的错误不是那么声明性的,测试必须等待很长时间。

例如,我应该测试onLayoutChildren方法LayoutManager。默认情况下,如果正确实施,此方法会在启动后执行两到三次,仅此而已。而且这个测试通过了 verify(spy, atMost(3)).onLayoutChildren(any(RecyclerView.Recycler.class), any(RecyclerView.State.class)),哪里spy来的间谍LayoutManager。行为可能被破坏并onLayoutChildren进入无限循环。如果在测试中出现错误,它会卡住。

我想要达到的目标。可能的变体是运行测试和应用程序一段时间(如 500 毫秒左右),然后中断应用程序并在此之后执行验证。没有任何连接到空闲

4

0 回答 0