android - how do you get an Idlingresource to work in Kotlin with coroutines -


my espresso idling resource not working - compiles , runs no longer waits long enough result returned 'net.


  1. start https://github.com/chiuki/espresso-samples/tree/master/idling-resource-okhttp
  2. convert main activity kotlin - test (which still in java) still works okhttpidlingresource
  3. convert anko coroutine call instead of retrofit.enqueue - test no longer works.

here new code mainactivity in entirety

import android.app.activity  import android.os.bundle  import android.widget.textview  import kotlinx.coroutines.experimental.android.ui  import kotlinx.coroutines.experimental.async  import org.jetbrains.anko.coroutines.experimental.bg    import retrofit2.retrofit  import retrofit2.converter.moshi.moshiconverterfactory    class mainactivity : activity() {      override fun oncreate(savedinstancestate: bundle?) {          super.oncreate(savedinstancestate)          setcontentview(r.layout.activity_main)          docallasync()      }        private fun docallasync() = async(ui) {            val user = bg { getuser() }          val name = user.await().name          val nameview = findviewbyid(r.id.name) textview            nameview.text = name;        }        private fun getuser(): user {            val retrofit = retrofit.builder()                  .baseurl("https://api.github.com/")                  .addconverterfactory(moshiconverterfactory.create())                  .client(okhttpprovider.getokhttpinstance())                  .build()            val service = retrofit.create(githubservice::class.java)              val response = service.getuser("chiuki").execute().body()            return response!!        }  }

convert anko coroutine call instead of retrofit.enqueue - test no longer works.

retrofit.enqueue uses okhttp's dispatcher. "idling-resource-okhttp" recognizes , communicates idlingresource manager.

however using retrofit.execute , anko's bg using different execution mechanism idlingresource manager not know about, while might executing application idle view of manager, ending test.

to fix need register idlingresource whatever execution mechanism bg uses, can recognize when there happening on thread of execution.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -