【发布时间】:2019-09-29 09:14:41
【问题描述】:
我开始使用 Koin,我需要测试一个 ViewModel,它要求存储库从手机的内部存储中检索文件。
当我设置 ViewModel 测试时,我正在做:
@Before
fun setup() {
startKoin {
modules(dataModule)
}
declareMock<Repository> {
fakeAccount = moshiAccountAdapter.fromJson(json)
whenever(this.getAccount()).thenReturn(fakeAccount)
}
}
但是存储库getAccount 方法是suspend fun getAccount(): Account?,所以我在ViewModelTest 类中遇到错误,说suspend function getAccount should be called only from a coroutine or from another suspending function。
提前致谢!
【问题讨论】:
标签: android kotlin kotlin-coroutines koin