我创建了一个影子类,它可以调用到真实对象中,如在 http:/robolectric.orgextending。:
@Implements(View::class)
class MyShadowView {
@RealObject
private lateinit var realView: View
@Implementation
fun animate(): ViewPropertyAnimator {
return realView.animate() // this call ends up calling my shadow's animate() function recursively
}
}
但是,当我的影子方法被执行时,它的结果是无限递归。
我做错了什么?
(我使用的是Robolectric 4.2.)
根据 http:/robolectric.orgjavadoc4.1orgrobolectricshadowapiShadow.html。 它应该是这样的。
@Implementation
fun animate(): ViewPropertyAnimator {
Shadow.directlyOn(realView, View::class.java).animate()
}