Reputation: 62519
I am using robolectric as my test runner with Mockito. I would like to know in Android how do i mock a resource. I have a array resource but in my test i'd like to mock the value.
i have an array that looks like this:
<array name="screen_sections">
<item>screen1</item>
<item>screen2</item>
<item>screen3</item>
<item>screen4</item>
</array>
and in test code i'd like to mock these values.
Upvotes: 5
Views: 5832
Reputation: 62519
I found a way to do this using Mockito.when
. So I would create a normal array and save it with my values, something like this works good:
CharSequence myNewArray = {"value1","value2","value3"}
Mockito.when(resources.getTextArray(someID)).thenReturn(myNewArray);
Upvotes: 5