-
Notifications
You must be signed in to change notification settings - Fork 90
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
Support for injecting mockito Spy objects without overriding modules #81
Comments
Hi, right now I think that the only solution available is to declare all three fields in the test, obviously it's a decent workaround only if there aren't other dependencies. Something like this:
DaggerMock will replace all the three objects in the module and it should work. About the final class issue, this is a problem related to the mockito usage on Kotlin, my suggestion to solve it is to use mockito inline dependency in JVM tests or Kotlin all open compiler plugin in Espresso tests. |
Thanks for the response, maybe i can help with a PR once i have some time.
I don't understand whats the difference and why it works in |
The instrumentations test are not executed on the jvm so mockito inline is not enough. You need to use kotlin all open or something similar. I think that the reason is something related to the mockito implementation and the differences between jvm and dalvik/art. |
i am not using mockito inline, rather using Dexopener. DaggerMockRule is what throws this error. |
@fabioCollini i added a PR which adds the spy feature to DaggerMock |
The error is thrown by DaggerMock because internally it uses Mockito. DexOpener should work, maybe you are defining your module in a package that it's not managed by DexOpener. You can find more details here: https://github.com/tmurakami/dexopener#limitations |
The package name of both the |
Thank you very much for the wonderful library. I have been playing around with it and i came across some limitations recently when i was trying to implement a UI test in
androidTest
package. i am usingdagger.android
and i want to inject some classes asspy
without specifically creating the test modules manuallyExample
What i want to do is that i have a
ProductRepository
and want to stub a few methods instead of mocking the wholeProductRepository
. I know something like this (Partial mocking) is possible by usingspy
instead ofmock
. My product repository has 2 dependencies and i want dagger to provide them instead of providing them manually for my spy object. Below is the code for my test project.CustomTestRunner
TestApplication
TestAppComponent
TestDaggerMockRule
I am unable to find a way to do this easily using
DaggerMock
. The only option i see is manually overriding theSpyRepositoryModule
which providesSpyProductRepository
. Can you tell me if there is any other simple way to do this without rewriting the modules ? (Which will provide me spies instead of real objects)SpyProductRepository
I would really like to not do this
Also another thing, If i remove
open
fromSpyProductRepository
which is located inside theandroidTest
package then i am getting the following error. It works fine if i move this class tomain
package where the app code resides then the error goes away. Super confusing :(Suggestion
Maybe the
DaggerMockRule
can take an boolean as constructor to provide spies for all dependencies or provide a method where we couldoverride
to provide all the dependencies that we couldspy
The text was updated successfully, but these errors were encountered: