https://kotlinlang.org logo
Title
h

Haus

02/14/2018, 11:21 PM
Does anyone here was able to overwrite any dependency on kodein for testing?
d

dave08

02/15/2018, 3:49 AM
#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

Lucas Ribeiro

02/15/2018, 11:27 AM
yes, I do a lot, just use bind(override = true) and should work
h

Haus

02/15/2018, 12:13 PM
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

Lucas Ribeiro

02/15/2018, 12:19 PM
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

Haus

02/15/2018, 12:22 PM
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

Lucas Ribeiro

02/15/2018, 12:30 PM
i do this in my test class, import my real module, then after that i override what I need to mock
val kodein : Kodein by Kodein.lazy {
 import(KodeinRealModule)
 bind<LoginRepository>(overrides = true) with provider { mockLoginRepository }
}
then I do
val loginRepository : LoginRepository = kodein.instance()
h

Haus

02/15/2018, 12:36 PM
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

Lucas Ribeiro

02/15/2018, 3:54 PM
i'm doing this on my unit test, no Application involved