本文介绍了单元测试 ArrayMap throws Method put in android.util.ArrayMap not mocked的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对使用数组映射的方法进行单元测试,但我不断收到以下异常:
I am trying to unit test a method that uses array map and I keep getting the following exception:
java.lang.RuntimeException: Method put in android.util.ArrayMap not mocked. See http://g.co/androidstudio/not-mocked for details.
代码:
ArrayMap<String, String> sampleMap =new ArrayMap<>();
for (SampleInfo info : details.getSampleList())
{
sampleMap.put(info.getkey(),info.getName());
}
我试过了:
testOptions {
unitTests.returnDefaultValues = true
}
这样可以避免异常,但地图始终为空.如何解决这个问题?
This way the exception is avoided but the map is always empty. How to resolve this issue?
推荐答案
为我工作,确保它在 build.gradle 的正确部分
Worked for me, make sure its in the correct part of the build.gradle
android {
...
testOptions {
unitTests.returnDefaultValues = true
}
}
这篇关于单元测试 ArrayMap throws Method put in android.util.ArrayMap not mocked的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!