I am trying to write a Junit test in Kotlin (Ktor) that would just verify the dependency graph. Currently there is only one Koin module, but my project is expected to have plenty more and as Koin does not have compile time checking of the dependencies I want to avoid the unexpected run-time errors.
But I am not sure how to use the verify function mentioned in the Koin documentation: https://insert-koin.io/docs/reference/koin-test/checkmodules as the documentation is not very clear on its usage.
I have a simple Koin module that defines some bindings.
Example file: sampleKoinModule.kt
val sampleKoinModule = module {
// Some binding definitions
}
I tried to something like this in my Junit test but it did not work:
class KoinDITest {
@Test
fun verifyDIGraph() {
val appModules = module {
includes(sampleKoinModule)
}
// The appModules module does not have a verify extension function
// and I am unable to use it
appModules.verify()
}
}
I have tried digging through the internet but all the resources that I have found have mostly replicated the example that is mentioned in the documentation. But, trying to do the same does not seem to work.
Below is the koin-test version that I am using:
<dependency>
<groupId>io.insert-koin</groupId>
<artifactId>koin-test</artifactId>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
Kindly let me know what I am doing wrong or if there is something other way of actually using the verify function.