The Koin DI Framework can be used with Kotest through the KoinListener test listener and its own interface KoinTest.

To add the listener to your project, add the dependency to your project:


With the dependency added, we can use Koin in our tests!

class KotestAndKoin : FunSpec(), KoinTest {
override fun listeners() = listOf(KoinListener(myKoinModule))
val userService by inject<UserService>()
init {
test("Use user service") {
userService.getUser().username shouldBe "LeoColman"