-
-
Notifications
You must be signed in to change notification settings - Fork 720
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
Using Koin for android tests #119
Comments
Hi all, |
Hi @patrice-conil, could be interesting to tell to Koin that we want mocks for given types 👍 |
In the snippet above, we can replace the snippet:
with:
I've just added |
Check #151 |
Can not see the createMock() function in koin test |
Sorry, it's has been renamed |
Searching for a solution to mock one of my repositories used as a Koin Module for instrumented tests, I finally found a way to mock it.
If you want to mock one of the Koin Modules for your instrumented test, you need to call the
loadKoinModules
method passing it a list of Koin Modules you want to override.The problem here is that if the Koin Module you want override is already injected inside the components you want to test, then the
loadKoinModules
won't have any effect on these components. So you have to make sure the Koin Module is not injected in your components before mocking it.A workaround I found is to override the
ActivityTestRule
you defined in your test class and to mock your Koin Module during thebeforeActivityLaunched
of theActivityTestRule
.This way, the Koin module will be mocked before activity is launched. As the module was injected once the Activity was created in my side, this solved the problem.
Here is my Test class including this solution:
It would be great to have such example inside the documentation :)
The text was updated successfully, but these errors were encountered: