Reputation:
If an uninstrumented unit test (not subclassed from AndroidTestCase) calls code that uses an ArrayMap, it hits the infamous Method xxx in xx.xx.xx not mocked
error (see http://tools.android.com/tech-docs/unit-testing-support#TOC-Method-...-not-mocked.-).
The best solution to this error in many cases is to compile the package containing the problematic class directly into the test target, eg. with json, adding to build.gradle:
testCompile 'org.json:json:20160212'
I don't know of any way to do this with ArrayMap, as unlike json it's actually part of the Android source. I don't think it's available externally (I haven't been able to find it on jcenter).
Any ideas? I don't want to run slow Android (instrumented) tests on the emulator just in order to test model layer classes that happen to use basic collection classes (and mocking their methods would seem insane!).
Upvotes: 4
Views: 396
Reputation: 27
One can use androidx.collection.ArrayMap
in place of android.util.ArrayMap
Upvotes: 1
Reputation: 887
The best work around I can think of is to use something like Apache's common collections, where they implement maps, such as their HasedMap. Kinda dumb to have to include another library to do something so simple.
Upvotes: 0