如何在 Android 中对手势进行单元测试?
我想在 Android 中对屏幕上向左/向右滑动的操作进行单元测试,但我找不到任何相关文档。有人可以帮忙吗?还可以做到吗?
I want to unit test a swipe left/right action on the screen in Android but I haven't been able to find any documentation on it. Can anyone lend a hand? Can it even be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,触摸将执行一个操作,您将测试该操作,而不是触摸本身。
Generally the touch will perform an action and you will be testing the action, not the touch itself.
我发现你的问题试图学习如何对完全相同类型的手势做完全相同的事情。我能够使用以下方法运行非常纯粹的单元测试。换句话说,单元测试 View.OnTouchListener.onTouch(View v, Event event) 函数。
以下是我如何“模拟”
View
和Event
以便运行onTouch
I found your question trying to learn how to do the exact same thing for the exact same type of gesture. I was able to run pretty pure unit tests using the following approach. In other words unit test
View.OnTouchListener.onTouch(View v, Event event)
function.Here is how I was able to "mock" the
View
andEvent
in order to runonTouch