Espresso Idling Resource
OkHttp Idling Resource with Retrofit
Up next
Previous
About
In this lesson you will learn how to use OkHttp Idling Resource to wait for Retrofit to finish fetching data from the internet.
In this lesson you will learn:
How to create a singleton OkHttp client for both your app and your test
How to pass the OkHttp client to Retrofit
How to create and use OkHttp Idling Resource in your Espresso test
Instructor
Links
Comments
I am trying to run this with androidx
in Kotlin, but it is not working!!
First I changed in app/build.gradle
:
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test:rules:1.1.0"
Then I changed the imports in file MainActivityTest.java
for the ones below:
import androidx.test.espresso.IdlingResource;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.rule.ActivityTestRule;
import com.jakewharton.espresso.OkHttp3IdlingResource;
import org.junit.Rule;
import org.junit.Test;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
But still, is not working!
You can use a wrapper to match the androidx type:
import androidx.test.espresso.IdlingResource
class Wrapper(private val r: OkHttp3IdlingResource): IdlingResource {
override fun getName(): String = r.name
override fun isIdleNow() = r.isIdleNow
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
}
}
Use the wrapper like this:
val idlingResource = Wrapper(OkHttp3IdlingResource.create("okhttp", OkHttpProvider.getOkHttpInstance()))
Also, I read this:
https://github.com/JakeWharton/okhttp-idling-resource/issues/19
So, if Jake Wharton didn't implemented this OkHttp for the androidx, well, how can we use it in Kotlin, and with androidx?