【发布时间】:2020-09-24 13:54:48
【问题描述】:
我正在编写 Robolectric 单元测试,我需要断言 ImageView 使用特定资源 ID 调用了 setImageResource(int)。我使用fest-android 进行断言,但它似乎不包含此断言。
我还尝试从 Robolectric 为 ImageView 获取 ShadowImageView,因为我知道它曾经让您可以访问它,但现在它已经消失了。
最后,我尝试在我的代码中调用 setImageDrawable 而不是 setImageResource,然后在我的测试断言中像这样:
assertThat(imageView).hasDrawable(resources.getDrawable(R.drawable.some_drawable));
但这也失败了,即使失败消息清楚地表明它是同一个 Drawable 正在加载。
【问题讨论】:
标签: android unit-testing robolectric