我正在为一个使用 android.util.Base64
的类编写单元测试,但是我遇到了这个错误:
java.lang.RuntimeException: Method encode in android.util.Base64 not mocked. See http://g.co/androidstudio/not-mocked for details.
at android.util.Base64.encode(Base64.java)
这是使用encode()
方法的代码:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// [write some data to the stream]
byte[] base64Bytes = Base64.encode(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
现在我明白了我不能在我的单元测试中使用Android库类。但是如何正确地模拟Base64
,以便我可以为我的类编写正确的单元测试呢?