https://kotlinlang.org logo
#android
Title
# android
a

Adam Kirk

04/10/2019, 2:23 AM
Anyone know if its possible to use Mockk to mock android.util.Base64 ?? I have 2 static functions encrypt and decrypt and would like to write unit test for them. https://stackoverflow.com/questions/55603438/mocking-java-base64-with-mockk
g

gildor

04/10/2019, 2:25 AM
Instead of mocking this class, just provide own abtraction for Base64
a

Adam Kirk

04/10/2019, 2:26 AM
??? Not sure I understand the error I get is ```
java.lang.RuntimeException: Method decode in android.util.Base64 not mocked. See http://g.co/androidstudio/not-mocked for details. at android.util.Base64.decode(Base64.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)
g

gildor

04/10/2019, 2:28 AM
Yes, because you use framework class in unit tests
There are few different workarounds for this, such as add Base64 implementation to your project and do not use framework, abstract this API
24 Views