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

Update the "Shadows" page #311

Merged
merged 1 commit into from
Sep 21, 2024
Merged

Conversation

MGaetan89
Copy link
Member

This PR updates the Shadows page.

This continues the work I've done on other pages:

  • Adding Kotlin code samples.
  • Adding links to other Robolectric pages and the Android documentation.
  • Removing outdated sections.

This PR updates the [Shadows](https://robolectric.org/extending/) page.

This continues the work I've done on other pages:
- Adding Kotlin code samples.
- Adding links to other Robolectric pages and the Android documentation.
- Removing outdated sections.
Comment on lines +5 to +7
1. Android native code cannot execute on your development machine.
2. There are no Android system services running on your development machine.
3. Android includes next to no APIs suitable for testing.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the leading texts since they didn't seem to bring any value.


### Using a Custom Shadows

Custom Shadows get hooked up to Robolectric using the `@Config` annotation on the test class or test method, using the `shadows` array attribute. To use the `MyShadowBitmap` class mentioned in the previous section, you would annotate the test in question with `@Config(shadows={MyShadowBitmap.class})`, and to include multiple custom shadows: `@Config(shadows={MyShadowBitmap.class, MyOtherCustomShadow.class})`. This causes Robolectric to recognize and use your custom shadow when executing code against the class you shadowed.
Custom Shadows get hooked up to Robolectric using the [`@Config`](javadoc/latest/org/robolectric/annotation/Config.html) annotation on the test class or test method, using the [`shadows`](javadoc/latest/org/robolectric/annotation/Config.html#shadows()) array attribute. To use the `MyShadowBitmap` class mentioned in the previous section, you would annotate the test in question with `@Config(shadows = { MyShadowBitmap.class })`. This causes Robolectric to recognize and use your custom shadow when executing code against the class you shadowed.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the example with multiple custom shadows, as it teaches more about Java syntax rather than Robolectric usage.

Comment on lines -195 to -196
### Don't use `useinheritImplementationMethods`
This is usually unnecessary and will be removed in [Robolectric 3.8](https://github.com/robolectric/robolectric/releases/tag/robolectric-3.8)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useinheritImplementationMethods doesn't seem to exist anymore (as documented), and Robolectric 3.8 is a rather old version now. So I've removed that section.

@MGaetan89 MGaetan89 merged commit 8fa517e into robolectric:master Sep 21, 2024
1 check passed
@MGaetan89 MGaetan89 deleted the update_shadows branch September 21, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants