Probably more of an AndroidStudio question... but....
# android
t
Probably more of an AndroidStudio question... but... This expression:
Copy code
Base64.decode("eF4Nzr1NBDEQQGEjQXot3FZw8nj8mxIcyUIAghTNeMawWsHB7SJ0HVABvdEANRDi_HvSO9s-0ki3o77vp7s8PrT7WU_m_Pfv5-v7Qj7UbKyiUCGEQiASLETHDBI4i8ekIXOBVCNgspxraYKIvrYQsYSKVIEzOxsokDbffZHCyQljlqjFJ3HNN6kdFK-xiPfJZhbHVYmsBfNGy9KnwGw92F5WdMm21neeD8s6idnsrk_D5fQ07Gkdro6q83Cj6-fhOJtXelFj_gHcOkP7", Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE)
In an InstrumentTest (so runs on the device) works fine. But run it from a simple unit test (which runs on the development box--mac os in this case--i believe), and it fails. returns null every time. Gives me the heeby jeebies about relying on unit tests.
p
Base64 is a class from the Android SDK, in unit tests (running on host machine) this is mocked and will return null. if you really need to test this functionality in unit tests you can use something like http://robolectric.org/ - however this will add latency to your unit tests
e
yes, Android framework is not available in local unit tests without something like Robolectric. if you set
android.testOptions.unitTests.returnDefaultValues = false
(the default), the stub Android framework will throw exceptions in local unit tests. you must have set it to
true
somewhere, which will cause those framework stub methods to return 0/null. see https://developer.android.com/training/testing/unit-testing/local-unit-tests for more details
t
10/10 recommend you use okio for all your base64 stuff. multi platform and super slick API's
e
if you're on a new enough minSdk≥26, there's also
java.util.Base64
which will work the same on desktop jvm and android. but okio.Base64 is nice and plays well with other okio constructs, if you're already using them that's an obvious choice
t
🙏 🙏
1
t
@ephemient Im interested in investigating
okio.Base64
in my current Android project, however I cannot identify which gradle dependency I require to include it in my project. Where am I going wrong??? I guessed it would be here
implementation group: 'com.squareup.okio', name: 'okio', version: '3.0.0-alpha.9'