小编sku*_*uch的帖子

如何修复 startKoin() 方法上的 NoSuchMethodError

我正在尝试使用 Koin DI 帮助启动测试,例如https://insert-koin.io/docs/2.0/documentation/koin-core/index.html#_making_your_test_a_koincomponent_with_kointesthttps://insert-koin.io /docs/2.0/getting-started/junit-test/ 但每次都得到NoSuchMethodError。我做错了什么?

首先,我使用包中已经创建的模块,但是出现了这个错误。然后我在测试包中创建了模块,但错误仍然相同。

我的代码

class ComponentA
class ComponentB(val a: ComponentA)

class SignInTest : KoinTest {

    val componentB : ComponentB by inject()

    @Before
    fun before() {
        startKoin { modules(
            module {
                single { ComponentA() }
                single { ComponentB(get()) }
            }) }
    }

    @Test
    fun test_test() {
        val componentA = get<ComponentA>()

        assertNotNull(componentA)
        assertEquals(componentA, componentB.a)
    }

    @After
    fun after() {
        stopKoin()
    }
Run Code Online (Sandbox Code Playgroud)

java.lang.NoSuchMethodError: org.koin.core.definition.BeanDefinition.(Lorg/koin/core/qualifier/Qualifier;Lorg/koin/core/qualifier/Qualifier;Lkotlin/reflect/KClass;)V

at net.app.at.features.signin.SignInTest$before$1$1.invoke(SignInTest.kt:79)
at net.app.at.features.signin.SignInTest$before$1$1.invoke(SignInTest.kt:26)
at org.koin.dsl.ModuleKt.module(Module.kt:31) …
Run Code Online (Sandbox Code Playgroud)

testing android unit-testing kotlin koin

2
推荐指数
1
解决办法
1849
查看次数

标签 统计

android ×1

koin ×1

kotlin ×1

testing ×1

unit-testing ×1