j2e*_*nue 5 android mockito robolectric
我使用 robolectric 作为 Mockito 的测试运行器。我想知道在 Android 中如何模拟资源。我有一个数组资源,但在我的测试中,我想模拟该值。
我有一个看起来像这样的数组:
<array name="screen_sections">
<item>screen1</item>
<item>screen2</item>
<item>screen3</item>
<item>screen4</item>
</array>
Run Code Online (Sandbox Code Playgroud)
在测试代码中,我想模拟这些值。
我找到了一种使用Mockito.when. 所以我会创建一个普通数组并用我的值保存它,这样的东西很好用:
CharSequence myNewArray = {"value1","value2","value3"}
Mockito.when(resources.getTextArray(someID)).thenReturn(myNewArray);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4163 次 |
| 最近记录: |