如何测试的按钮点击,改变了活动的看法异步结果呢?按钮、看法、改变了、结果

2023-09-14 00:04:16 作者:你没资格追姐

我尝试写一些活动测试的应用程序,我想测试一个特殊的情况是,当我点击某个按钮时,活动视图相应更新。但是,单击该按钮会稍微长时间运行的异步任务开始后,才任务完成不认为改变。

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.