https://kotlinlang.org logo
#chucker
Title
# chucker
v

voben

05/30/2020, 5:46 AM
How do I use Chucker together with mockwebserver? I’m currently trying to test my token interceptor for okhttp using mockwebserver, and that works when the token interceptor is the only interceptor. But when I add chucker, my code hangs when I call
mockWebServer.takeRequest()
. I’m currently mocking chucker. Is that what I should be doing? Here’s what my okhttpclient creation code looks like. Any ideas would be great
Copy code
fun createOkHttpClient(tokenInterceptor: TokenInterceptor, chuckerInterceptor: ChuckerInterceptor): OkHttpClient {

    val builder = OkHttpClient.Builder().addInterceptor(tokenInterceptor)

    if (BuildConfig.DEBUG) {
        builder.addInterceptor(chuckerInterceptor)
    }
    return builder.build()
}
👍 1
v

Vova Buberenko

05/30/2020, 7:17 AM
Hey there. What happens is you try to put only Chucker interceptor in your tests? Does it work? If no, it might be something wrong in the code. We also use mockwebserver to test Chucker interceptor class and it works fine there. You can take a look here if it is helpful: https://www.github.com/ChuckerTeam/chucker/tree/develop/library%2Fsrc%2Ftest%2Fjava%2Fcom%2Fchuckerteam%2Fchucker%2Fapi%2FChuckerInterceptorTest.kt
3 Views