Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I unit test Koin Modules?

I'm using Koin as my DI framework in an Android project and I want to unit test my modules.

For example: if a class A depends on B and C, test that B and C are being included in the Koin graph and that I'm properly injecting them in the module.

Is it possible?

like image 977
Rod Avatar asked Oct 16 '25 16:10

Rod


1 Answers

If you are using Junit, you can and it's very simple:

Add the Koin Android dependency like below:

// Add Maven Central to your repositories if needed
repositories {
    mavenCentral()    
}

dependencies {
    
    // Koin for Tests
    testImplementation "io.insert-koin:koin-test-junit4:$koin_version"
}

Your test class:

class CheckModulesTest : KoinTest {

    @Test
    fun checkAllModules() {
        appModule.verify()
    }
}

You can check the documentation on the Verifying Your App section

like image 185
Leonardo Sibela Avatar answered Oct 18 '25 07:10

Leonardo Sibela