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

Document how to use a Roboelectric test dependency for Android unit tests that use pbandk #208

Open
garyp opened this issue Feb 15, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation platform-android
Milestone

Comments

@garyp
Copy link
Collaborator

garyp commented Feb 15, 2022

If pbandk's JSON functionality (e.g. Message.encodeToJsonString()) is used from within an Android unit test, the unit test fails to run because the JVM used for running unit tests does not have an android.util.Base64 implementation. android.* dependencies are only available to tests in the androidTest source set, which run on real or emulated devices rather than on the local JVM.

Robolectric provides a robust way to run unit tests that include Android dependencies on the JVM by simulating many Android APIs without running an actual device; but it requires using the Robolectric test runner and modifying tests to initialize the simulated environment appropriately. However, there is a lighter-weight way of using Robolectric if UI-related Android APIs aren't needed (Context, Activity, etc.). In that case, all that's needed is a dependency on the platform-specific Robolectric runtime library:

testRuntimeOnly("org.robolectric:android-all:11-robolectric-6757853")

If the above dependency is added to the Android project that uses pbandk, then pbandk's JSON-related methods will run successfully from unit tests.

@garyp garyp added the documentation Improvements or additions to documentation label Feb 15, 2022
@garyp garyp added this to the 1.0 milestone Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation platform-android
Projects
None yet
Development

No branches or pull requests

1 participant