Ser*_*ici 3 android mocking robolectric actionbarsherlock
我正在尝试使用Robolectric为使用SherlockActionBar的应用程序编写测试.如果选择了一个应用程序,我需要测试应用程序是否正确MenuItem,但是android.view.MenuItem当应用程序使用该方法时,Robolectric lib仅提供模拟onOptionItemSelected(com.actiombarsherlock.view.MenuItem).
所以我的问题是:
可能有可用性来嘲笑com.actionbarsherlock.view.MenuItem?
或者是变通方法还是什么?
提前致谢...
所以......因为没有更优雅的方式来嘲笑com.actionbarsherlock.view.MenuItem我这样做了:
com.actionbarsherlock.view.MenuItemMenuItem界面中的其他方法留空(可能我将在其他测试中使用它们)结果我得到了这样的测试:
com.actionbarsherlock.view.MenuItem item = new TestSherlockMenuItem(R.id.some_action);
activity.onOptionsItemSelected(item);
ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
Intent startedIntent = shadowActivity.getNextStartedActivity();
assertNotNull(startedIntent);
ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent);
assertThat(shadowIntent.getComponent().getClassName(),
equalTo(NextActivity.class.getName()));
Run Code Online (Sandbox Code Playgroud)
顺便说一句,感谢Eugen Martynov试图理解我的问题:)
| 归档时间: |
|
| 查看次数: |
666 次 |
| 最近记录: |