使用JUnit4和Robolectric 3.0_rc3使用SupportMapFragment测试片段,我无法运行测试。你能明白为什么吗?
地图片段在片段的onCreateView中实例化。测试包括:
MyFragment subject = new MyFragment();
SupportFragmentTestUtil.startVisibleFragment(subject);
与robolectric核心一起,我在build.gradle文件中包含了robolectric:shadows-maps和robolectric:shadows-support-v4。我项目中的所有其他测试工作正常。这是错误堆栈的相关部分:
android.content.res.Resources$NotFoundException: String resource ID #0x7f0c001b
at android.content.res.Resources.getText(Resources.java:239)
at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:358)
at android.content.res.Resources.getText(Resources.java)
at android.content.res.Resources.getString(Resources.java:325)
at com.google.android.gms.common.internal.zzf.zzh(Unknown Source)
at com.google.android.gms.common.internal.zzf.zzh(Unknown Source)
at com.google.android.gms.dynamic.zza.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:130)
at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:29)
at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:95)
at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:230)
at org.robolectric.util.Scheduler.postAtFrontOfQueue(Scheduler.java:98)
at org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:114)
at android.os.MessageQueue.enqueueMessage(MessageQueue.java)
at android.os.Handler.enqueueMessage(Handler.java:623)
at android.os.Handler.sendMessageAtTime(Handler.java:592)
at android.os.Handler.sendMessageDelayed(Handler.java:563)
at android.os.Handler.post(Handler.java:323)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1384)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
at org.robolectric.util.SupportFragmentTestUtil.startVisibleFragment(SupportFragmentTestUtil.java:24)
资源ID是指名为common_google_play_services_install_text_phone的Google Play资产。资产在我的项目目录中生成,也存在于com.google.android.gms,com.google.android.gms.location和com.google.android.gms.maps中。
非常感谢任何帮助!
答案 0 :(得分:0)
问题解决了。在将Robolectric从2.4更新到3.0后,配置似乎已过时。本文后面有很多帮助:
http://evendanan.net/robolectric/unit-test/2015/04/09/migrating-to-robolectric-v3/