尝试使用Koin注入方法运行单元测试时。我被抛出异常java.lang.IllegalStateException: KoinApplication has not been started
。我遵循了Koin文档here
我的课如下
class MyTest: AbstractBaseTestClass(), KoinTest {
private val myViewModel: MyViewModel by inject()
private val myDataRepository: MyDataRepository by inject()
@Before
fun before() {
startKoin {
modules(appModules)
}
myDataRepository.initialize()
}
@After
fun after() {
stopKoin()
}
@Test
fun testViewModel() {
myViewModel.doSomething()
}
}