使用JUnit4和Robolectric 3.0_rc3以SupportMapFragment測試片段,我無法獲得測試運行。你能明白爲什麼嗎?Android Google Maps測試(JUnit4 + Robolectric 3.0)無法運行;資源未找到異常
映射片段在片段的onCreateView中實例化。該測試包括眼前這個:
MyFragment subject = new MyFragment();
SupportFragmentTestUtil.startVisibleFragment(subject);
隨着robolectric核心,我已經包括robolectric:陰影,地圖和robolectric:在我的build.gradle文件陰影支持-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。該資產是在我的項目目錄中生成的,也存在於com.google.android.gms,com.google.android.gms.location和com.google.android.gms.maps中。
任何幫助將不勝感激!