Skip to content

What is resource idling

Devrath edited this page Feb 28, 2024 · 4 revisions

What is resource Idling

  • Espresso is a very popular testing framework that allows developers to write concise and reliable UI tests.
  • Sometimes when we are writing the UI tests, we notice that we might need to add some delay when executing the tests just to avoid flaky tests.
  • Basically in UI tests, We need to ensure one action completes before another action starts.
  • when we have used espresso, It already synchronously handled things.
  • But sometimes there are other scenarios, Where there is the possibility of Asynchronous mechanisms running in the background to be handled, In such cases resource idling comes into play.

Common use-cases of resource idling

  • Loading the data from the server or a local storage.
  • Establishing the connections with the database and handling the callbacks.
  • Performing complex logic, and bitmap operations that consume time.

Visualization of Logic behind the testing of time-consuming function

  • We define a customClass that extends IdlingResource.
  • Now in the constructor of this class, We pass the implementation that takes time-consuming work.
  • We later use isIdleNow() overridden function and callback to determine the state of the idling resource
  • Now in the test case we initialize the idling resource and keep it ready say better would be @Before
  • Now We call the test case to perform the required action, and call the idling resource to start the time-consuming work and complete it
  • The control will stay until the idling resource has finished execution.
  • Finally in the next line we perform assertion.