PreferenceRoom icon indicating copy to clipboard operation
PreferenceRoom copied to clipboard

Robolectric Testing

Open Dalakoti07 opened this issue 3 years ago • 3 comments

Hi @skydoves, I am using the library and injecting component like this the fragment with Hilt as DI framework. @Inject lateinit var appSettingsComponent: PreferenceComponent_AppSettingsComponent

Now I am creating corresponding test class for this fragment, but I am unable to mockk the component class and inject in the fragment.

One of the possible solution is to uninstall the PrefModule and bind own fake AppSettingComponentImpl.

@skydoves is there a better than creating fakes, un-installing and binding the fake implementation.

Some magic stuff which works out of the box

Dalakoti07 avatar Feb 02 '22 09:02 Dalakoti07

Hi @Dalakoti07! I think creating mocked component/entity implementations is the best solution now. ​ If I find any nicer solutions, I'll share them with you!

skydoves avatar Feb 02 '22 15:02 skydoves

Thanks

Dalakoti07 avatar Feb 02 '22 16:02 Dalakoti07

Hi @skydoves

Can you please tell exactly how to mock component/entity implementation.

  • I am using mockk
  • Hilt as a DI framework
  • And I am injecting PreferenceComponent with field injection in fragment
  • I have create a PrefsModule, and doing integration tests with robolectric

One of the boolean value is false by default (which is a happy path), I want to test unhappy-path, where boolean is true.

How can I achieve this?

Dalakoti07 avatar Feb 04 '22 08:02 Dalakoti07