Issue
The Android Studio recommends me to use SparseIntArray
instead of Hashmap<Integer, Integer>
from standard Java.
SparseIntArray
map 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.
Solution
You should use Robolectric framework if you want to test class with platform dependencies: http://robolectric.org/
Answered By - Atetc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.