Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robolectric Testing #27

Open
Dalakoti07 opened this issue Feb 2, 2022 · 3 comments
Open

Robolectric Testing #27

Dalakoti07 opened this issue Feb 2, 2022 · 3 comments

Comments

@Dalakoti07
Copy link

Dalakoti07 commented Feb 2, 2022

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 Dalakoti07 changed the title Roboelectric Testing Robolectric Testing Feb 2, 2022
@skydoves
Copy link
Owner

skydoves commented Feb 2, 2022

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!

@Dalakoti07
Copy link
Author

Thanks

@Dalakoti07
Copy link
Author

Dalakoti07 commented Feb 4, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants