gpt4 book ai didi

android - 使用 Retrofit 网络请求时如何使用 IdlingResource 测试 Android UI

转载 作者:IT老高 更新时间:2023-10-28 23:21:13 27 4
gpt4 key购买 nike

我正在编写集成测试,在 UI 中执行操作,使用 Retrofit 启动网络调用。

我知道我需要实现 CountingIdlingResource ,但我想以正确的方式进行(如果已经完成,则不要重新发明轮子)。

是否有人在其应用的 Espresso 测试套件中实现了 IdlingResource 以等待网络请求执行?

更多信息 here .

最佳答案

对此最直接的解决方案:基本上是用 AsyncTask 替换 Retrofit 的线程池执行器(如 linked Google group discussion 中非常有帮助的 Nick 推荐的那样)。我是这样做的:

new RestAdapter.Builder()
.setEndpoint(LOCLSET_SERVER_URL)
.setExecutors(AsyncTask.THREAD_POOL_EXECUTOR,
new MainThreadExecutor())
.build();

我不确定这是否是最合适的解决方案,但它是我能开始工作的最快最理智的解决方案。请记住,这仅适用于 ICS+。

关于android - 使用 Retrofit 网络请求时如何使用 IdlingResource 测试 Android UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23142437/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com