2

I have an app built with Retorift2 + Dagger2. I started to write Android UI tests using Espresso. To wait for a netwoking calls I need to register an IdlingResource. I have added dependency to OkHttp3IdlingResource.

I need to Inject a OkHttp in my test class, but as AppComponent is not in the same source directory so I can't just add

void inject(RegistrationLoginUiTest activity);

To my component.

How can I get OkHttp from the dependency graph into my test class?

Is the only way to create TestAppComponent and swap it with the AppComponent?

Vadims Savjolovs
  • 2,618
  • 1
  • 26
  • 51
  • add in `build.gradle` file dependencies: `androidTestCompile 'javax.inject:javax.inject:1'` – piotrek1543 Aug 26 '16 at 20:56
  • then use your `provide...` methods. Just after `inject` set like this `OkHtttp ok = ....inject(RegistrationLoginUiTest activity).provideOkHttpCLient()`. – piotrek1543 Aug 26 '16 at 20:58

1 Answers1

1

I have sorted out that in any case if I want to inject test class I should create TestAppComponent where I should add line:

void inject(RegistrationLoginUiTest activity);

And then swap TestAppComponent with AppComponent

Vadims Savjolovs
  • 2,618
  • 1
  • 26
  • 51