如何测试异步更改活动视图的按钮单击结果? [英] How can I test the result of a button click that changes the Activity's view asynchronously?

查看:11
本文介绍了如何测试异步更改活动视图的按钮单击结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为应用编写一些活动测试,我想测试的一个特定场景是,当我单击某个按钮时,活动视图会相应更新.但是,单击该按钮会启动一个运行时间较长的异步任务,并且只有在该任务完成后,视图才会更改.

I am trying to write some Activity tests for an app, and one particular scenario that I want to test is that when I click a certain button, the Activity view updates accordingly. However, clicking the button causes a somewhat long running asynchronous task to start and only after that task is completed does the view change.

我该如何测试?我目前正在尝试使用 ActivityInstrumentationTestCase2 类来完成此操作,但无法弄清楚如何让测试等待"直到按钮单击任务的异步部分完成并且视图更新.

How can I test this? I'm currently trying to use the ActivityInstrumentationTestCase2 class to accomplish this, but am having trouble figuring out how to have the test 'wait' until the asynchronous part of the button click task is complete and the view updates.

推荐答案

我最终通过使用 Robotium 库的 Solo.waitForText 方法接受字符串和超时时间并阻塞,直到出现预期文本或超时发生.很棒的 UI 测试库.

I ended up solving this by using the Robotium library's Solo.waitForText method that takes a string and timeout period and blocks until either the expected text appears or the timeout occurs. Great UI testing library.

这篇关于如何测试异步更改活动视图的按钮单击结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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