You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Koin 3.1.0, the checkModules() extension function which takes a lambda has been removed, breaking compatibility with existing code. What follows is my attempts to understand the new API.
One can try to migrate the checkModules() call like so:
org.koin.core.error.BrokenDefinitionException: Definition is broken: [Singleton:'Box']
- due to error: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'java.lang.String'. Check your definitions!
I guess defaultValues doesn't work how I might expect. What is the real replacement for create<Box> { parametersOf("foo") }?
This isn't exactly what I want, but let's try putting the parameter directly in the graph.
val koinApplication = startKoin {
modules(module {
single { Box(get()) }
single { "foo" }
})
}
koinApplication.checkModules()
This fails with a missing MockProvider:
Definition is broken: [Singleton:'Box']
- due to error: java.lang.IllegalStateException: Missing MockProvider. Please use MockProvider.register() to register a new mock provider
But why do I need a MockProvider when nothing in the graph needs to be mocked?
Ok, so let's try it this way:
val koinApplication = startKoin {
modules(module {
single { Box(get()) }
single { "foo" }
})
}
MockProvider.register {
when (it) {
String::class->"bar"else-> error("unknown type!")
}
}
koinApplication.checkModules()
This finally works on JVM, but I remain confused. It fails if single { "foo" } is omitted but actually creates a Box using "bar". I don't understand why it uses a mock instead of the value already on the graph. Furthermore, using MockProvider in that way obviously won't scale very well. I guess it's intended to plug in something like Mockk or Mockito but that's only possible on JVM.
Also, that test doesn't work on Native, but fails with
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen org.koin.test.mock.MockProvider@38510278
In fact, it's impossible to register a mock provider on Native because this involves mutating state in a top-level object which is not allowed by the current memory model.
All told, I find these API breakages confusing and I don't understand how to migrate my koin tests using checkModules() from 3.0.2 to 3.1.0.
The text was updated successfully, but these errors were encountered:
The following is a valid test on both JVM and Native in Koin version 3.0.2 using the
koin-core
andkoin-test
modules.In Koin 3.1.0, the
checkModules()
extension function which takes a lambda has been removed, breaking compatibility with existing code. What follows is my attempts to understand the new API.One can try to migrate the
checkModules()
call like so:This fails with the following message:
I guess defaultValues doesn't work how I might expect. What is the real replacement for
create<Box> { parametersOf("foo") }
?This isn't exactly what I want, but let's try putting the parameter directly in the graph.
This fails with a missing
MockProvider
:But why do I need a
MockProvider
when nothing in the graph needs to be mocked?Ok, so let's try it this way:
This finally works on JVM, but I remain confused. It fails if
single { "foo" }
is omitted but actually creates aBox
using "bar". I don't understand why it uses a mock instead of the value already on the graph. Furthermore, usingMockProvider
in that way obviously won't scale very well. I guess it's intended to plug in something like Mockk or Mockito but that's only possible on JVM.Also, that test doesn't work on Native, but fails with
In fact, it's impossible to register a mock provider on Native because this involves mutating state in a top-level object which is not allowed by the current memory model.
All told, I find these API breakages confusing and I don't understand how to migrate my koin tests using
checkModules()
from 3.0.2 to 3.1.0.The text was updated successfully, but these errors were encountered: