I have a problem with Koin & "androidTest". Because androidTest starts the Application I don't need to start Koin by myself in the test.
Now I need to inject a mock service. The problem is, that I inject inside of a method with get()
inside of a singleton class and this is not working via constructor injection because the injected object can have different implementations.
My idea was to declare what I need this way:
declare {
factory<Webservice>(override = true) { mockWebservice }
}
But this will be applied on all tests. That's why an other test, which checks if the correct class was injected failed.
I also tried to use stopKoin()
, startKoin(listOf(appModule))
in the @After
method, but with this the dependency injection doesn't work anymore in later tests.
Is there a way to declare the mock only for one test?