遵循this教程在Eclipse ADT中设置Robolectric并使用Sonatype中的2.1.1版
在运行教程中概述的基本测试时,我得到以下堆栈跟踪:
java.lang.RuntimeException: really, more than 64 qualifiers?!?
at org.robolectric.res.ResBunch.pick(ResBunch.java:45)
at org.robolectric.res.ResBunch.getValue(ResBunch.java:40)
at org.robolectric.res.XResourceLoader.getValue(XResourceLoader.java:54)
at org.robolectric.res.PackageResourceLoader.getValue(PackageResourceLoader.java:5)
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:263)
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:259)
at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:62)
at android.content.res.AssetManager.getResourceText(AssetManager.java)
at android.content.res.Resources.getText(Resources.java:225)
at android.content.res.Resources.getString(Resources.java:313)
at android.text.format.DateUtils.getDayOfWeekString(DateUtils.java:325)
at android.text.format.DateFormat.format(DateFormat.java:473)
at android.text.format.DateFormat.format(DateFormat.java:422)
at com.test.project.HomeScreenActivity.setCheckinDate(HomeScreenActivity.java:505)
at com.test.project.HomeScreenActivity.onCreate(HomeScreenActivity.java:148)
at android.app.Activity.performCreate(Activity.java:5008)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:119)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at com.test.project.HomeScreenActivityTest.setUp(HomeScreenActivityTest.java:18)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
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:177)
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)
控制台的输出如下:
DEBUG: Loading resources for com.test.project from .\res...
DEBUG: Loading resources for com.squareup.timessquare from .\..\android-times-square\library\res...
DEBUG: Loading resources for android from jar:C:\Users\me\.m2\repository\org\robolectric\android-res\4.1.2_r1_rc\android-res-4.1.2_r1_rc-real.jar!/res...
INFO: no id mapping found for android:drawable/scrollbar_handle_horizontal; assigning ID #0x1140002
INFO: no id mapping found for android:drawable/scrollbar_handle_vertical; assigning ID #0x1140003
INFO: no id mapping found for android:color/highlighted_text_light; assigning ID #0x1140004
INFO: no id mapping found for android:color/hint_foreground_light; assigning ID #0x1140005
INFO: no id mapping found for android:color/link_text_light; assigning ID #0x1140006
INFO: no id mapping found for android:color/dim_foreground_light_disabled; assigning ID #0x1140007
INFO: no id mapping found for android:color/dim_foreground_light; assigning ID #0x1140008
INFO: no id mapping found for android:color/bright_foreground_light; assigning ID #0x1140009
INFO: no id mapping found for android:layout/text_edit_paste_window; assigning ID #0x114000a
INFO: no id mapping found for android:layout/text_edit_no_paste_window; assigning ID #0x114000b
INFO: no id mapping found for android:layout/text_edit_side_paste_window; assigning ID #0x114000c
INFO: no id mapping found for android:layout/text_edit_side_no_paste_window; assigning ID #0x114000d
INFO: no id mapping found for android:layout/text_edit_suggestion_item; assigning ID #0x114000e
INFO: no id mapping found for android:color/bright_foreground_light_disabled; assigning ID #0x114000f
INFO: no id mapping found for android:color/highlighted_text_dark; assigning ID #0x1140010
INFO: no id mapping found for android:color/hint_foreground_dark; assigning ID #0x1140011
INFO: no id mapping found for android:color/link_text_dark; assigning ID #0x1140012
INFO: no id mapping found for android:color/bright_foreground_dark_disabled; assigning ID #0x1140013
INFO: no id mapping found for android:color/bright_foreground_dark; assigning ID #0x1140014
INFO: no id mapping found for android:color/bright_foreground_dark_inverse; assigning ID #0x1140015
INFO: no id mapping found for android:drawable/spinner_background_holo_light; assigning ID #0x1140016
INFO: no id mapping found for android:color/dim_foreground_dark_disabled; assigning ID #0x1140017
INFO: no id mapping found for android:color/dim_foreground_dark; assigning ID #0x1140018
INFO: no id mapping found for android:color/dim_foreground_dark_inverse_disabled; assigning ID #0x1140019
INFO: no id mapping found for android:color/dim_foreground_dark_inverse; assigning ID #0x114001a
INFO: no id mapping found for android:drawable/progress_medium_white; assigning ID #0x114001b
INFO: no id mapping found for android:drawable/spinner_white_48; assigning ID #0x114001c
INFO: no id mapping found for android:color/primary_text_light_disable_only; assigning ID #0x114001d
从jar加载资源时,似乎robolectric失败:C:\ Users \ ahobbs \ .m2 \ repository \ org \ robolectric \ android-res \ 4.1.2_r1_rc \ android-res-4.1.2_r1_rc-real。 jar!/ res ...我不知道如何解决这个问题。
这是我的Test类:
package com.test.project
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
@RunWith(org.robolectric.RobolectricTestRunner.class)
public class HomeScreenActivityTest {
private HomeScreenActivity mActivity;
@Before
public void setUp() throws Exception {
mActivity = Robolectric.buildActivity(HomeScreenActivity.class).create().get();
}
@Test
public void shouldHaveHappySmiles() throws Exception {
String hello = mActivity.getResources().getString(R.string.test);
assertThat(hello, equalTo("test"));
}
}
如何更正此问题并让我的简单测试与Robolectric一起运行?
答案 0 :(得分:0)