voghdev
04/05/2017, 10:24 AMvoghdev
04/05/2017, 10:51 AMMethod getMainLooper in android.os.Looper not mocked
error. Will push my code in a secvoghdev
04/05/2017, 10:53 AMelizarov
04/05/2017, 4:18 PMUserDetailPresenter.initialize
from fun initialize() { launch(CommonPool) { … } }
to fun initialize() = launch(CommonPool) { … }
, e.g. make it return the corresponding Job
(you’ll need to change its super-class, too)
2. Now in your test code do it like this:
fun myTestForSomething() = runBlocking<Unit> { // this line !!!
…
presenter.initialize().join() // wait for intilize job to complete!
}
Now you should not need to introduce delayvoghdev
04/06/2017, 10:00 AMlaunch
and runBlocking
as you suggested. Tests seem to be passing without the delay(30); Just one more question about launch(UI)
. Is it necessary to use it if I want to notify results in UI thread? If I uncomment lines 39, 42 to call launch(UI)
, tests are not passing anymore https://github.com/voghDev/HelloKotlin/blob/coroutines3/app/src/main/java/es/voghdev/hellokotlin/UserDetailPresenter.ktelizarov
04/06/2017, 11:07 AMlaunch(UI)
or replace CommonPool
with UI
on line 35