Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to load modules immediatly for Android instrumented tests #1318

Closed
christophehenry opened this issue Mar 22, 2022 · 4 comments
Closed
Labels
android documentation status:checking currently in analysis - discussion or need more detailed specs
Milestone

Comments

@christophehenry
Copy link

christophehenry commented Mar 22, 2022

Is your feature request related to a problem? Please describe.
As the documentation states, on Android, Koin is started by the Application class which means that loaded modules are the same for every instrumentation tests.

The documentation states that "loadModules and unloadModules are often unsafe because the changes are not applied immediately" which means that modules can't reliebly be swapped — for instance by a mock — for the course of one or a series of specific tests.

It is not clear here if createEagerInstances() and singles createdAtStart parameter provide a partial solution to that problem by always immediatly creating singleton modules.

Describe the solution you'd like
loadModules and unloadModules could provide a executeImmediatly for swapping modules with immediate exectution.

Target Koin project
Koin

@gmk57
Copy link

gmk57 commented May 24, 2022

Yes, we're looking for it too!

The topic of proper Koin setup for instrumented tests is discussed for almost two years, but sill lacks a perfect solution.

Part of the problem is probably the vague documentation: "recommended approach is to add a module of your overrides to modules used by startKoin in the application's Application class".

Where should we do that?

Adding instrumentedTestModule in production Application is neither possible nor desirable. Docs probably mean using a special Application class for tests via manifest or test runner, but this is not said clearly.

I find it strange compared to very clear & practical Koin documentation in general (yes, we're looking at you, Dagger ;)).

@christophehenry
Copy link
Author

Docs probably mean using a special Application class for tests via manifest or test runner, but this is not said clearly.

I think docs mean via test runner, which is what I use. The first problem is this solution seems not described anywhere in Android's documentation (I found my answer on StackOverflow). The second is there is no way to load different modules for different tests. The runner and thus the Application is the same for all the instrumented tests. You can't isolate one module for one test, for instance, in order to mock it.

Currently, for me, singleton module seem to escape this problem since you can create them eagerly and, looking at the code, they are always loaded as soon as you call loadModules when creating them eagerly. So you can call loadModules in @Before functions reliably. But this is not official.

@arnaudgiuliani arnaudgiuliani added this to the 3.3.0 milestone Jun 27, 2022
@arnaudgiuliani arnaudgiuliani added the status:checking currently in analysis - discussion or need more detailed specs label Jun 27, 2022
@arnaudgiuliani
Copy link
Member

Yes, should have more precise point on it

@arnaudgiuliani
Copy link
Member

Please follow updated doc introduced in #1409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android documentation status:checking currently in analysis - discussion or need more detailed specs
Projects
None yet
Development

No branches or pull requests

3 participants