我试图学习Robolectric
。所以我正在测试在Eclipse上创建的应用程序。
该项目使用Parse-1.7.1.jar
来接收推送通知。我按照instructions设置了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项目中(属性&gt; java构建路径&gt;库&gt;添加外部jar),但它不起作用。
如果您需要更多信息,请与我们联系。我希望你能帮助我。
答案 0 :(得分:1)
我遇到了同样的问题,所以我创建了一个评论ParsePushBroadcastReceiver
的TestApplication,它有效。
请注意,您必须将Test
放在应用程序名称之前(创建新类并复制粘贴原始应用程序)。
像这样:
public class TestMyMoneyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//ParseCrashReporting.enable(getApplicationContext());
Parse.enableLocalDatastore(this);
Parse.initialize(this, "", "");
//ParsePush.subscribeInBackground("");
}
}
这就是你需要做的一切。 只是为了澄清,这是一种解决方法,我没有找到问题的解决方案!