Koin: checkModules fails if some modules are using Android stuff

Created on 24 Sep 2018  路  1Comment  路  Source: InsertKoinIO/koin

We have an android application with several modules. Some of them are pure kotlin modules and another ones are Android modules.

In the main module (android application), we want to have a test using checkModules function from Koin to check if injection is valid but it fails.

Error is about Room and other Android stuff implemented in some Android modules.

Must this be managed by Koin? Is there another option than do a mock over each android dependency?

question

Most helpful comment

Hello @Moussenger ,

try to add an Android mock module, to add to your modules when checking with checkModules():

val mockedAndroidContext = module {
        single { mock(Application::class.java) }
    }

This will give a mock instance of Application. Also give a single { mock(Context::class.java) } if you inject Context instance.

>All comments

Hello @Moussenger ,

try to add an Android mock module, to add to your modules when checking with checkModules():

val mockedAndroidContext = module {
        single { mock(Application::class.java) }
    }

This will give a mock instance of Application. Also give a single { mock(Context::class.java) } if you inject Context instance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sankarsana picture sankarsana  路  4Comments

ILAgent picture ILAgent  路  3Comments

AHarazim picture AHarazim  路  3Comments

CristianMG picture CristianMG  路  3Comments

luna-vulpo picture luna-vulpo  路  4Comments