首先,我想聲明我對Android缺乏適當的測試基礎結構感到沮喪......或者我可能會被推遲,我不知道...
I最終成功設置了android-test-plugin,並且我爲一個活動編寫了一些測試,其中包括一個CustomMapFragment
,這是我寫的延伸SupportMapFragment
的課程。
我所有的測試,試圖讓使用此活動的一個實例:
在Android Studio中使用Robolectric問題進行Android測試
activity = Robolectric.buildActivity(MyActivity.class).create().get();
失敗:
java.lang.NoClassDefFoundError: com/google/android/gms/maps/GoogleMap$OnInfoWindowClickListener
在活動的setContentView
。
活動的XML如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<fragment
android:id="@+id/customMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.myproject.CustomMapFragment"/>
</RelativeLayout>
有沒有一種解決方法/解決方案? 任何幫助,將不勝感激。
我分享你的無奈。我有同樣的問題,但我無法運行任何測試,因爲當Robolectric嘗試加載類時,我在地圖類上得到了NoClassDefFoundError,所以即使是assertTrue(true)測試也會失敗。這是我的問題與我得到的錯誤http://stackoverflow.com/questions/18434217/robolectric-fails-to-run-tests-with-google-play-services-maps – alex
我認爲這是一個普遍問題,不直接連接到地圖,因爲我在某些使用Google雲消息的類中遇到了同樣的錯誤。很高興知道有人理解你:)以防有人在這裏回答我會告訴你。 –
你是如何添加谷歌播放服務依賴項?使用谷歌資料庫或以另一種方式? – alex