我不熟悉将 Robolectric 与 Maven 一起用于 Android 项目。
这是测试用例(它实际上并没有做任何事情)
@RunWith(RobolectricTestRunner.class)
public class UTest {
private SplashActivity mActivity;
@Before
public void setUp() throws Exception {
mActivity = Robolectric.buildActivity(SplashActivity.class).create().get();
ProgressBar bar = (ProgressBar) mActivity.findViewById(R.id.signInProgress);
}
@Test
public void testingMe() throws Exception {
}
}
但是,当使用目标测试针对 Maven 运行时,我得到以下异常:
java.lang.IllegalStateException: immutable!
at org.robolectric.res.ResBundle$ResMap.merge(ResBundle.java:128)
at org.robolectric.res.ResBundle$ResMap.access$100(ResBundle.java:116)
at org.robolectric.res.ResBundle.mergeLibraryStyle(ResBundle.java:88)
at org.robolectric.res.OverlayResourceLoader.doInitialize(OverlayResourceLoader.java:26)
at org.robolectric.res.XResourceLoader.initialize(XResourceLoader.java:29)
at org.robolectric.res.XResourceLoader.getValue(XResourceLoader.java:53)
at org.robolectric.res.OverlayResourceLoader.getValue(OverlayResourceLoader.java:58)
at org.robolectric.res.RoutingResourceLoader.getValue(RoutingResourceLoader.java:31)
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 ****.loadRestServerUrl(****.java:417)
at ****.onCreate(****.java:201)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:146)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:387)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:227)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
有谁知道是什么问题?我正在使用 Robolectric 2.1.1。