使用 Espresso 测试可绘制更改 [英] Using Espresso to test drawable changes

查看:30
本文介绍了使用 Espresso 测试可绘制更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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 Drawables, 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 Drawables. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆