Skip to content Skip to sidebar Skip to footer

Unit Testing 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 ht

Solution 1:

Worked for me, make sure its in the correct part of the build.gradle

android {

  ...

  testOptions { 
     unitTests.returnDefaultValues = true
  }
}

Solution 2:

As @ShadowFlame stated on above comment I used array map support "androidx.collection.ArrayMap" instead of "android.util.ArrayMap" and it works fine.

Solution 3:

You can try because it is ArrayMap using key value/pair

ArrayList<ArrayMap<String, String>> listArray2 = newArrayList<>();
        for (SampleInfo info1 : details.getSampleList())
        {
            sampleMap.put("keyname",info1.getName());

            listArray2.add(sampleMap);

        }
        Log.e("****sadflkj **",listArray2.toString());

Post a Comment for "Unit Testing Arraymap Throws Method Put In Android.util.arraymap Not Mocked"