Robolectric 3.1 中缺少 ShadowViewTreeObserver

ShadowViewTreeObserver missing in Robolectric 3.1

Robolectric 3.0 提供了 ShadowViewTreeObserver class,但 Robolectric 3.1 中没有。

官方升级指南 (https://github.com/robolectric/robolectric/wiki/3.0-to-3.1-Upgrade-Guide) 讲述了由于 Android API 功能重复而删除的影子方法,但那里没有提到 ShadowViewTreeObserver

这个 class 是怎么回事?是否应该使用 Android API ViewTreeObserver 的方法来代替 3.1 中的这个特殊影子?

是的,在Robolectric3.1.x中没有更多ShadowViewTreeObserverclass,检查:Overview.

merge 请求中解释了此更改的原因 Deleting ShadowViewTreeObserver as it reimplements what the real class does. #2308,其中只有一个名为

的提交

如您所见,问题的答案将提交: https://github.com/robolectric/robolectric/pull/2308/commits/e10bddd18ebb3df14423d3743e11772e4fd76e49.

您可能会感兴趣的是,它只有一个提交,名称中有解决方案,因为它被称为 Deleting ShadowViewTreeObserver. Please use the real class moving forward

tells about shadow methods being removed due to duplication of Android API funtionalities, yet ShadowViewTreeObserver is not mentioned there.

他们好像忘了更新他们的文档 ;-)

希望对您有所帮助