代码来源于 youtube 视频:https://www.youtube.com/watch?v=_96FT7E6PL4&list=PLgCYzUzKIBE_ZuZzgts135GuLQNX5eEPk&index=15&t=4s
Espresso idling resources
有时候我们进行异步操作任务,然后用返回的结果更新 UI, 这是常见的情况。这个时候,如果在进行 UI test,由于结果还没返回,这个是就会失败。
为了解决这个问题,就需要用到 idling resources 解决。
idling resources 常用的场景
idling resources 常用的实现类
CountingIdlingResource
Maintains a counter of active tasks. When the counter is zero, the associated resource is considered idle. This functionality closely resembles that of a Semaphore. In most cases, this implementation is sufficient for managing your app’s asynchronous work during testing.
UriIdlingResource
Similar to CountingIdlingResource, but the counter needs to be zero for a specific period of time before the resource is considered idle. This additional waiting period takes consecutive network requests into account, where an app in your thread might make a new request immediately after receiving a response to a previous request.
IdlingThreadPoolExecutor
A custom implementation of ThreadPoolExecutor that keeps track of the total number of running tasks within the created thread pools. This class uses a CountingIdlingResource to maintain t