2014-12-28 105 views
0

我在努力學習Robolectric。所以我正在測試在Eclipse上創建的應用程序。 該項目使用Parse-1.7.1.jar接收推送通知。我按照這些instructions設置了robolectric。然而,當我嘗試運行測試我得到這個異常:Robolectric和外部罐子

java.lang.IllegalStateException: In order to use the ParsePush.subscribe or ParsePush.unsubscribe methods you must add the following to your AndroidManifest.xml: 
<receiver android:name="com.parse.ParsePushBroadcastReceiver" 
    android:exported="false"> 
    <intent-filter> 
    <action android:name="com.parse.push.intent.RECEIVE" /> 
    <action android:name="com.parse.push.intent.OPEN" /> 
    <action android:name="com.parse.push.intent.DELETE" /> 
    </intent-filter> 
</receiver> 
(Replace "com.parse.ParsePushBroadcastReceiver" with your own implementation if you choose to extend ParsePushBroadcastReceiver) 
at com.parse.ParsePush.checkForManifestAndThrowExceptionIfNeeded(ParsePush.java:152) 
at com.parse.ParsePush.subscribeInBackground(ParsePush.java:78) 
at com.parse.ParsePush.subscribeInBackground(ParsePush.java:99) 
at mx.com.ronda.test.RondaApplication.onCreate(RondaApplication.java:25) 
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126) 
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440) 
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

我的Android項目上沒有明顯宣佈ParsePushBroadcastReceiver因爲我擴展它。我嘗試將Parse作爲外部jar添加到我的測試java項目(屬性> java構建路徑>庫>添加外部jar),但它不起作用。

讓我知道你是否需要更多信息。我希望你能幫助我。

回答

1

我有同樣的問題,所以我創建了一個TestApplication評論ParsePushBroadcastReceiver,它工作。

請注意,您必須在應用程序名稱(創建一個新類並複製粘貼原始應用程序)之前放置Test

像這樣:

public class TestMyMoneyApplication extends Application { 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     //ParseCrashReporting.enable(getApplicationContext()); 
     Parse.enableLocalDatastore(this); 
     Parse.initialize(this, "", ""); 
     //ParsePush.subscribeInBackground(""); 
    } 
} 

這就是所有你需要做的。 只是爲了澄清,這是一種解決方法,我沒有找到解決問題的辦法!

+0

OMG它的工作!非常感謝。最後一件事,請告訴我爲什麼可行,或者指出解釋該文檔的文檔? – ILovemyPoncho

+0

老實說,我不知道爲什麼ParsePush不起作用,我仍在深入研究。如果我在這件事上發現了什麼,我會在這裏編輯我的答案並留下評論! – Leonardo

+0

再次感謝Leo – ILovemyPoncho