我有一个使用Robolectric 1.1和Roboguice 2的测试套件。它运行良好。
我在应用程序清单中添加了一个AppWidget:
<receiver android:name="NearestOpenCragWidgetProvider" android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/nearest_open_crag_widget_info" />
</receiver>
我创建了一个类
public class NearestOpenCragWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
//get the layout
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.nearest_open_crag_widget);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
}
和res / xml中的AppWidgetProviderInfo xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" >
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/nearest_open_crag_widget"
android:resizeMode="none">
</appwidget-provider>
并添加了布局nearest_open_crag_widget
现在,当我运行测试时,他们会立即失败
java.lang.ArrayIndexOutOfBoundsException: -1
at com.xtremelabs.robolectric.ApplicationResolver.replaceLastDotWith$IfInnerStaticClass(ApplicationResolver.java:55)
at com.xtremelabs.robolectric.ApplicationResolver.registerBroadcastReceivers(ApplicationResolver.java:47)
at com.xtremelabs.robolectric.ApplicationResolver.resolveApplication(ApplicationResolver.java:36)
at com.xtremelabs.robolectric.RobolectricTestRunner.createApplication(RobolectricTestRunner.java:491)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:368)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:307)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:285)
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.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)
应用程序的目标是2.3,如果我在Android Manifest中注释掉Widget声明,测试会再次开始运行。
我显然有一些屁股倒退,并想知道这个蠢货是否能发现它。
答案 0 :(得分:1)
原来问题应该是'如何添加小部件提供商而不是白痴'。如果我在android清单中使用提供者的完全限定名称,那么一切都很好
<receiver android:name="uk.co.some.package.NearestOpenCragWidgetProvider" android:exported="false">
<blah />
</receiver>