https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Shankar

06/29/2020, 1:38 PM
Is there any way to test getAccessToken() method through mockito,
Copy code
getAccessToken(): String {

    val token: String
    //check token expiry...
    runBlocking {
        token = getToken()
    }
    return token
}

getToken(): String = suspendCoroutine { continuation->
    //get the token from server and return it
    continuation.resume(newToken)
}
I tried to mock the getToken() method, but the runBlocking{} block never gets called.
j

Javier

06/29/2020, 2:35 PM
Check Mockk library, it has support for coroutines
e

Evan R.

06/29/2020, 3:05 PM
Yeah, mockito doesn’t have the best coroutine support, better to use mockk like @Javier said
6 Views