Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Last active May 17, 2020 22:06
Show Gist options
  • Select an option

  • Save cdmunoz/b94f616a5cbddc9b2c0753c56823da89 to your computer and use it in GitHub Desktop.

Select an option

Save cdmunoz/b94f616a5cbddc9b2c0753c56823da89 to your computer and use it in GitHub Desktop.
Calling EspressoIdlingResource increment and decrement to from prod code to let Espresso know while runnig UI tests when idling resources are available to continue its execution
//HomeFragment logic and methods
//Calls increment before the query to API
private fun initViewModels() {
if (null == photosViewModel) {
//creates viewModel
//.....
EspressoIdlingResource.increment()
photosViewModel?.loadData()
}
}
private fun initObservers() {
photosViewModel?.getPhotos()?.observe(viewLifecycleOwner, Observer { result ->
when (result) {
is Result.Success -> {
renderList(result.data)
EspressoIdlingResource.decrement()
binding.homePhotosProgressContainer.visibility = View.GONE
binding.homePhotosList.visibility = View.VISIBLE
}
is Result.InProgress -> {
//InProgress logic
}
is Result.Error -> {
//Error logic
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment