The Android Studio recommends me to use SparseIntArray instead of Hashmap<Integer, Integer> from standard Java.
SparseIntArraymap integers to integers. Unlike a normal array of integers, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Integers, both because it avoids auto-boxing keys and values and its data structure doesn't rely on an extra entry object for each mapping.
I think it really fits my code, but I cannot use any methods containing this class in Local Unit Tests. I always end with RuntimeException...
java.lang.RuntimeException: Method put in android.util.SparseIntArray not mocked. See http://g.co/androidstudio/not-mocked for details.
at android.util.SparseIntArray.put(SparseIntArray.java)
...
Is there any way to import this method for local testing? I don't think it uses any Android's features. The unitTests.returnDefaultValues = true only returns default values for all calls. I know I can use Instrumented Unit Tests but it slows down the testing process.
You should use Robolectric framework if you want to test class with platform dependencies: http://robolectric.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With