1

我正在调查 Robolectric 测试失败的问题。失败的附加信息不是永久性的——如果我只为这个类运行测试,它们就会通过,如果我运行所有测试,它们就会失败。堆栈跟踪如下:

android.view.InflateException: XML file ./res/layout/welcome_footer.xml line #-1 (sorry, not yet implemented): Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.ViewStub.inflate(ViewStub.java:258)
at android.view.ViewStub.setVisibility(ViewStub.java:234)
at com.ebuddy.android.commons.ui.PreziActivity.onCreate(PreziActivity.java:49)
at com.ebuddy.android.xms.ui.WelcomeActivity.onCreate(WelcomeActivity.java:197)
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:117)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:124)
at com.ebuddy.android.xms.ui.WelcomeActivityTest.testOnStopFinishFlurryLogger(WelcomeActivityTest.java:84)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor89.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.ViewStub.$$robo$$ViewStub_24fd_inflate(ViewStub.java:258)
at android.view.ViewStub.inflate(ViewStub.java)
at android.view.ViewStub.$$robo$$ViewStub_24fd_setVisibility(ViewStub.java:234)
at android.view.ViewStub.setVisibility(ViewStub.java)
at com.ebuddy.android.commons.ui.PreziActivity.onCreate(PreziActivity.java:49)
at com.ebuddy.android.xms.ui.WelcomeActivity.onCreate(WelcomeActivity.java:197)
at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008)
at android.app.Activity.performCreate(Activity.java)
at sun.reflect.GeneratedMethodAccessor182.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:117)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:124)
at com.ebuddy.android.xms.ui.WelcomeActivityTest.testOnStopFinishFlurryLogger(WelcomeActivityTest.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
... 29 more
 Caused by: java.lang.RuntimeException: unknown font id 3
at org.robolectric.shadows.ShadowTypeface.findById(ShadowTypeface.java:101)
at org.robolectric.shadows.ShadowTypeface.nativeCreateFromTypeface(ShadowTypeface.java:55)
at android.graphics.Typeface.nativeCreateFromTypeface(Typeface.java)
at android.graphics.Typeface.create(Typeface.java:123)
at android.widget.TextView.setTypeface(TextView.java:1233)
at android.widget.TextView.setTypefaceFromAttrs(TextView.java:1148)
at android.widget.TextView.__constructor__(TextView.java:1065)
at android.widget.TextView.<init>(TextView.java:447)
at android.widget.Button.<init>(Button.java:107)
at android.widget.Button.<init>(Button.java:103)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.ViewStub.inflate(ViewStub.java:258)
at android.view.ViewStub.setVisibility(ViewStub.java:234)
at com.ebuddy.android.commons.ui.PreziActivity.onCreate(PreziActivity.java:49)
at com.ebuddy.android.xms.ui.WelcomeActivity.onCreate(WelcomeActivity.java:197)
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:117)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:124)
at com.ebuddy.android.xms.ui.WelcomeActivityTest.testOnStopFinishFlurryLogger(WelcomeActivityTest.java:84)
... 29 more
4

1 回答 1

2

根本原因是原生Typeface类和ShadowTypeface都有缓存,但是每个测试用例只清除ShadowTypeface的缓存,导致缓存不一致。

此拉取请求已修复此问题。请查看最新的 Robolectric。

于 2013-09-19T05:44:20.930 回答