I've posted a question some days ago and I'm still...
# dagger
j
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.
w
The setup looks correct except this piece:
Copy code
fun create(@BindsInstance application: TestApp)
I think you should be binding
application: App
j
Woops, yes, that was an issue.
Good catch tho.
w
With that, does it still make real requests?
j
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
w
Did you verify with debugger that retrofit instance gets
localhost:8080
as base url?
j
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.
w
It doesn’t seem like a Dagger issue to me then
j
Well, I guess there's something missing about Dagger
since I can not use like okHttpClient from the test, I've tried :
Copy code
@Inject
    lateinit var okHttpClient: OkHttpClient
And it says that is not initialized
Do I have to inject the TestApp somewhere?
I've tried this
Copy code
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