[Updated] Fix unlinked android injector factories#211
[Updated] Fix unlinked android injector factories#211nodejsjs wants to merge 6 commits intoJakeWharton:masterfrom nodejsjs:rs/fix-unlinked-android-injector-factories
Conversation
| public class ExampleFragmentInjectionActivityTest { | ||
| @Test | ||
| public void activityFragmentInjection() { | ||
| try (ActivityScenario<ExampleFragmentInjectionActivity> scenario = launch(ExampleFragmentInjectionActivity.class)) { | ||
| scenario.moveToState(CREATED); | ||
| scenario.onActivity(activity -> { | ||
| ExampleFragment fragment = (ExampleFragment) activity.getFragmentManager().findFragmentByTag("ExampleFragment"); | ||
| assertThat(fragment.string).isEqualTo("Hello!"); | ||
| assertThat(fragment.aLong).isEqualTo(10L); | ||
| assertThat(fragment.anInt).isEqualTo(20); | ||
| }); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This test is failing when the task :integration-tests:android-has-interface:testReflectDebugUnitTest is run. But as a single test run from the IDE, it passes just fine. Any hints please on what might be going on here? @JakeWharton
There was a problem hiding this comment.
It's probably because of moveToState. launch may have an optional parameter for initial state like Fragment, even if it doesn't, the default initial state may be RESUMED. I think you are going to DESTROYED with this code. Just an idea, not fully sure.
Also you may need to idle the looper, since Robolectric 4.4.
There was a problem hiding this comment.
Thanks for the pointers! I'm gonna investigate the Fragment/ActivityScenario apis more. I should add that it fails with the following error:
No injector factory bound for Class<com.example.ExampleFragment>
java.lang.IllegalArgumentException: No injector factory bound for Class<com.example.ExampleFragment>
at dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:136)
at dagger.android.support.AndroidSupportInjection.inject(AndroidSupportInjection.java:75)
at dagger.android.support.AndroidSupportInjection.inject(AndroidSupportInjection.java:67)
at com.example.ExampleFragment.onAttach(ExampleFragment.java:34)
Updated PR for #196 #174
Credits to @crgarridos and @kokeroulis