DaggerMock icon indicating copy to clipboard operation
DaggerMock copied to clipboard

Why is DaggerMock trying to mock all objects in the graph?

Open bnvinay92 opened this issue 6 years ago • 2 comments
trafficstars

Mockito cannot mock/spy because :

  • final class

I have an object that is being passed into a subcomponent with @BindsInstance. DaggerMock is trying to mock this object even though I don't want to mock it in tests, and this is causing my test to crash.

bnvinay92 avatar Jan 24 '19 10:01 bnvinay92

Are you sure the error is on the object used in a @BindsInstance annotated method? However if you are using DaggerMock in a Kotlin project you should consider using something to avoid problems with final methods/classes. More info here: https://github.com/fabioCollini/DaggerMock/#kotlin-support

fabioCollini avatar Jan 24 '19 13:01 fabioCollini

@Subcomponent.Builder
    interface Builder {

        @BindsInstance
        Builder activity(AppCompatActivity activity);

        // Everything breaks when I add the following.
        @BindsInstance
        Builder lifecycleEvents(SomeFinalClassFromALibraryICantMakeOpen object);

        ActivityComponent build();
    }

I'm not trying to mock this final class in my UI tests, so why does it matter if the object being bound is final or not?

mock-maker-inline does not seem to work with androidTests.

bnvinay92 avatar Jan 24 '19 17:01 bnvinay92