Hi, I'm migrating my project to Kotlin 1.3 and Cor...
# coroutines
p
Hi, I'm migrating my project to Kotlin 1.3 and Coroutines 1.0. Most of it is painless but I have troubles to make my unit tests to work again. Before (with coroutines 0.30.2), I had the following code (simplified)
Copy code
@Test
fun mockSuspendUnitTest = runBlocking {
  given(presenter.present()).will { throw Error() } // presenter.present() is a suspend fun
  
  // when
  viewModel = MyViewModel(presenter)
  
  // then
  viewModel.errorLiveData.observeForever(errorObserver)
  then(errorObserver).should().onChanged("error")
}
with the ViewModel :
Copy code
class MyViewModel(presenter: MyPresenter): ScopedViewModel() {

  val errorLiveData = MutableLiveData<String>()
  init {
    load()
  }

  private fun load() {
    launch {
      try {  
        presenter.present()
      } catch(e: Exception) {
        errorLiveData.postValue("error")
      }
    }
  }  
}
But with 1.0.0-RC1, the
presenter.present()
call in the ViewModel is no longer mocked properly and my exception is never thrown.