mardi 10 novembre 2020

How to add Coroutines idling resource

i am using Espresso for my UI tests and when the espresso test tries to access Coroutines, it crashes with error Test instrumentation process crashed. Check ...txt for details.

I am guessing it is crashing as the test cannot handle background thread and io thread.

I am basically calling a UseCase which does API call in a background thread and passes the result in Main thred.

How can i solve this

I have read about idling resource but never used one for coroutines.

this is my usecase which uses coroutines

when ever an api call is made, invoke function is called which does the job in IO thread and passes the result in Main thred

UseCaseCoroutine<out Type, in Params> where Type : Any {

    abstract suspend fun run(params: Params): Type

    operator fun invoke(params: Params, onResult: (type: Type) -> Unit = {}) {
        val job = GlobalScope.async(Dispatchers.IO) { run(params) }
        GlobalScope.launch(Dispatchers.Main) { onResult(job.await()) }
    }

    class None
}

Any idea how to make espresso tests pass

thanks a ton in advance R

Aucun commentaire:

Enregistrer un commentaire