How to inject mocks with Dagger 2.11

Viewed 1059

I am trying to inject mocks using the Android Injector of Dagger 2.11.

Before using the Android Inject I used to change the injector in the Application class so I can inject mocks. Like this:

class EGOApplication : Application() {

    lateinit var injectorComponent: InjectorComponent


    override fun onCreate() {
        super.onCreate()

        injectorComponent = DaggerInjectorComponent.builder()
                .appModule(AppModule(this))               
                .build()
}

And in my tests I used to change the injectorComponent like this:

app.injectorComponent = DaggerMockComponent.builder()
                .mockModule(MockModule(app))
                .build()

And then I can inject my mocks from MockModule.

But now I am using Android Injector form this tutorial: https://medium.com/@iammert/new-android-injector-with-dagger-2-part-1-8baa60152abe

Well... now I inject my dependencies like this:

override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
}

So my approach doesn't work anymore... How can I make Dagger injector dependencies from my MockModule?

Any help is appreciated!

1 Answers
Related