Ondřej Kycelt
11/17/2023, 9:27 PMcheckModules()
and I got into a situation where I keep getting NoBeanDefFoundException
. I have three classes, two of which are declared in a module. In test, I provide the third class mock using withInstance<Outsider>()
. But for some reason, checkModules()
throws NoBeanDefFoundException: No definition found for type 'com.test.di.Outsider'. Check your Modules configuration and add missing type and/or qualifier!
. Does anybody know why? I guess it’s related to the parameter which the factory for First
requires. When I remove the parameter, checkModules()
says it’s all good. Thanks in advance for any help.
data class Outsider(val version: String)
data class First(val outsider: Outsider, val booleanParam: Boolean)
data class Second(val first: First)
val testModule = module {
factory { (booleanParam: Boolean) ->
First(
outsider = get(),
booleanParam = booleanParam
)
}
factory {
Second(
first = get { parametersOf(true) }
)
}
}
class TestModuleTests {
@get:Rule
val mockProvider = MockProviderRule.create { clazz ->
mockkClass(clazz, relaxed = true)
}
@Test
fun checkModules() {
koinApplication {
modules(testModule)
checkModules {
withInstance<Outsider>()
}
}
}
}
LeoColman
11/17/2023, 9:35 PMwithInstance<Outsider>()
to some point before checkModules()?LeoColman
11/17/2023, 9:35 PMcheckModules
is building the tree before executing your functionOndřej Kycelt
11/17/2023, 9:39 PMwithInstance<T>()
is a function on ParametersBinding
. So it needs to be called from checkModules {}
.Ondřej Kycelt
11/18/2023, 2:30 PMFirst
in checkModules()
like the documentation says, but I'm still getting the same error.
@Test
fun checkModules() {
koinApplication {
modules(testModule)
checkModules {
withInstance<Outsider>()
withParameters<First> { parametersOf(false) }
}
}
}