使用Espresso测试可绘制的更改 [英] Using Espresso to test drawable changes
问题描述
我是Espresso测试的新手,但似乎没有任何方法可以测试可绘制的更改.
I'm new to Espresso testing, but there doesn't seem like there's any way to test drawable changes.
我有一个教程,是一个ImageView
Drawable
幻灯片演示,被塞进"一个半透明的TextView
中.在我的测试中,我想确保在按下下一个按钮时,已将正确的Drawable
插入到教程的ImageView
中.
I have a tutorial that is an ImageView
Drawable
slideshow 'tucked into' a semi-transparent TextView
. In my tests, I want to ensure that when the next button is pressed, the proper Drawable
has been inserted into the tutorial's ImageView
.
没有默认的Matcher
用于检查Drawable
,因此我着手使用 https://stackoverflow.com/a/28785178/981242 .不幸的是,由于无法检索ImageView
的活动Drawable
的ID,因此我无法完成matchesSafely()
的实现.
There is no default Matcher
to check for Drawable
s, so I set out to write my own using https://stackoverflow.com/a/28785178/981242. Unfortunately, since there is no way to retrieve the id of an ImageView
's active Drawable
, I can't complete the matchesSafely()
implementation.
这不是测试活动的Drawable
的唯一用例.人们在这种情况下通常使用什么工具?
This can't be the only use case for testing active Drawable
s. What is the tool that people normally use for situations like this?
推荐答案
我不希望比较位图,而应遵循以下答案的建议: https://stackoverflow.com/a/14474954/1396068
I prefer not to compare bitmaps and instead follow this answer's advice: https://stackoverflow.com/a/14474954/1396068
设置图像视图的可绘制对象时,还要使用setTag(R.drawable.your_drawable)
将可绘制对象ID存储在其标记中.然后使用Espresso的withTagValue(equalTo(R.drawable.your_drawable))
匹配器检查标签是否正确.
When setting the image view's drawable, also store the drawable ID in its tag with setTag(R.drawable.your_drawable)
. Then use Espresso's withTagValue(equalTo(R.drawable.your_drawable))
matchers to check for the correct tag.
这篇关于使用Espresso测试可绘制的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!