Thread
#dagger
    Joan Colmenero

    Joan Colmenero

    2 years ago
    I've posted a question some days ago and I'm still looking for a proper solution, the thing is that I'm trying to create a TestAppComponent because when creating UI tests and doing the call it's not using the mockWebServer is doing the real call, any help is appreciate: https://stackoverflow.com/questions/61539234/dagger2-not-injecting-instance-on-test
    Edited the question with more details.
    wasyl

    wasyl

    2 years ago
    The setup looks correct except this piece:
    fun create(@BindsInstance application: TestApp)
    I think you should be binding
    application: App
    Joan Colmenero

    Joan Colmenero

    2 years ago
    Woops, yes, that was an issue.
    Good catch tho.
    wasyl

    wasyl

    2 years ago
    With that, does it still make real requests?
    Joan Colmenero

    Joan Colmenero

    2 years ago
    The dispatcher is not firing when the call is done
    I mean, I've created a dispatcher to mock the response, but even if I put the correct url is not stopping there
    wasyl

    wasyl

    2 years ago
    Did you verify with debugger that retrofit instance gets
    localhost:8080
    as base url?
    Joan Colmenero

    Joan Colmenero

    2 years ago
    well, I have an interceptor that tells me that the call is to that endpoint.
    I mean, it's this base_url + the following path, so I guess it's ok.
    wasyl

    wasyl

    2 years ago
    It doesn’t seem like a Dagger issue to me then
    Joan Colmenero

    Joan Colmenero

    2 years ago
    Well, I guess there's something missing about Dagger
    since I can not use like okHttpClient from the test, I've tried :
    @Inject
        lateinit var okHttpClient: OkHttpClient
    And it says that is not initialized
    Do I have to inject the TestApp somewhere?
    I've tried this
    val instrumentation = InstrumentationRegistry.getInstrumentation()
            val app = instrumentation.targetContext.applicationContext as App
    
            val testComponent = DaggerTestAppComponent.factory().create(app).inject(app)
    But it still saying the same... I can not use any
    @inject