簡體   English   中英

Robolectric測試在shadowOf上失敗

[英]Robolectric tests fail on shadowOf

可能是什么問題? 我的Robolectric測試前一陣子運行良好,但現在它們都因相同的錯誤而失敗。 我能想到的唯一更改是更改為2.1.1版。 我使用RobolectricTestRunner運行它們,運行配置指向實際的應用程序目錄。

但是每次測試都失敗,因為在訪問首選項時,應用程序的應用程序類始終為null:

java.lang.NullPointerException: can't get a shadow for null
        at org.robolectric.bytecode.ShadowWrangler.shadowOf(ShadowWrangler.java:414)
        at org.robolectric.Robolectric.shadowOf_(Robolectric.java:1077)
        at org.robolectric.Robolectric.shadowOf(Robolectric.java:483)
        at org.robolectric.shadows.ShadowPreferenceManager.getDefaultSharedPreferences(ShadowPreferenceManager.java:21)
        at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java)
        at com.foo.bar.FooApplication.onCreate(FooApplication.java:90)

顯然是由於這個原因導致了我的應用程序類的onCreate錯誤:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

getBaseContext()更改為此 ,測試將再次工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM