KoinApplication尚未启动

时间:2019-07-26 16:11:08

标签: android unit-testing junit koin

尝试使用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()
        }

    }

0 个答案:

没有答案