sku*_*uch 2 testing android unit-testing kotlin koin
我正在尝试使用 Koin DI 帮助启动测试,例如https://insert-koin.io/docs/2.0/documentation/koin-core/index.html#_making_your_test_a_koincomponent_with_kointest或https://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)
at org.koin.dsl.ModuleKt.module$default(Module.kt:29)
at net.app.at.features.signin.SignInTest$before$1.invoke(SignInTest.kt:36)
at net.app.at.features.signin.SignInTest$before$1.invoke(SignInTest.kt:26)
at org.koin.core.context.GlobalContextKt.startKoin(GlobalContext.kt:72)
at net.app.at.features.signin.SignInTest.before(SignInTest.kt:35)
Run Code Online (Sandbox Code Playgroud)
小智 5
请检查您正在使用的 Koin 库的版本。
我有同样的问题。事实证明,我在 build.gradle 中有:
implementation "org.koin:koin-android:2.0.0-beta-1"
Run Code Online (Sandbox Code Playgroud)
和下面的几行:
testImplementation "org.koin:koin-test:2.0.0"
Run Code Online (Sandbox Code Playgroud)
当我在两个地方都设置了 2.0.0 版时 - 它起作用了。
| 归档时间: |
|
| 查看次数: |
1849 次 |
| 最近记录: |