Does anyone here was able to overwrite any depende...
# android
h
Does anyone here was able to overwrite any dependency on kodein for testing?
d
#kodein is better, but I think there's an override param in bind() and in module declaration. It's all in the docs. You don't have to come on to configurable kodein for this...
l
yes, I do a lot, just use bind(override = true) and should work
h
I have all the binds normally but i need to mock one dependency by overrinding it.. i've already tried this(override = true) with extend(appkodein()) but its still not working
l
which error message you receive ?
bind<MyClass>() with provider { MyClass()}
should be override by
bind<MyClass>(overrides = true) with provider {mock(MyClass::class.java)}
without problems
h
I'm not getting any error..it's only not working... If i do that as foi said it will work fine but i want to do do that inside my test...
I retrieve the graph dependency and then i extend it and add another bind with the overrides=true and keeps reaching the real and not the fake one
l
i do this in my test class, import my real module, then after that i override what I need to mock
Copy code
val kodein : Kodein by Kodein.lazy {
 import(KodeinRealModule)
 bind<LoginRepository>(overrides = true) with provider { mockLoginRepository }
}
then I do
val loginRepository : LoginRepository = kodein.instance()
h
did you do this only with module, didn't you?
i'm trying to avoid it
You are doing this inside the application? val kodein : Kodein by Kodein.lazy { import(KodeinRealModule) bind<LoginRepository>(overrides = true) with provider { mockLoginRepository } }
l
i'm doing this on my unit test, no Application involved