添加ProgressBar时Robolectric测试失败(sdk 26)

时间:2017-11-16 12:10:54

标签: android robolectric

我遇到使用sdk 26运行robolectric测试用例的问题。测试运行正常,但是当我将ProgressBar添加到相应的布局时,该片段的所有测试用例(包含进度条布局)开始失败。

此外,如果我使用@Config将sdk更改为25,则即使在布局中使用ProgressBar,测试也会通过。

使用的Robolectric版本:

testCompile 'org.robolectric:robolectric:3.4.2'
testCompile 'org.robolectric:shadows-multidex:3.3.2'
testCompile 'org.robolectric:shadows-support-v4:3.3.2'

Android支持库:26

请在下面找到有关失败问题的日志:

    android.view.InflateException: XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar

    Caused by: android.view.InflateException: XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.$$robo$$createView(LayoutInflater.java:647)
    at android.view.LayoutInflater.createView(LayoutInflater.java)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:164)
    at android.view.LayoutInflater.$$robo$$onCreateView(LayoutInflater.java:720)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:148)
    at android.view.LayoutInflater.$$robo$$createViewFromTag(LayoutInflater.java:788)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
    at android.view.LayoutInflater.$$robo$$inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragment.onCreateView(InsightsFragment.java:73)
    at android.support.v4.app.Fragment.$$robo$$performCreateView(Fragment.java:2343)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$moveToState(FragmentManager.java:1419)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$moveFragmentToExpectedState(FragmentManager.java:1740)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$moveToState(FragmentManager.java:1809)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
    at android.support.v4.app.BackStackRecord.$$robo$$executeOps(BackStackRecord.java:799)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$executeOps(FragmentManager.java:2580)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$executeOpsTogether(FragmentManager.java:2367)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$removeRedundantOperationsAndExecute(FragmentManager.java:2322)
    at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$execPendingActions(FragmentManager.java:2229)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl$1.$$robo$$run(FragmentManager.java:700)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java)
    at android.os.Handler.$$robo$$handleCallback(Handler.java:789)
    at android.os.Handler.handleCallback(Handler.java)
    at android.os.Handler.$$robo$$dispatchMessage(Handler.java:98)
    at android.os.Handler.dispatchMessage(Handler.java)
    at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:164)
    at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:31)
    at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:138)
    at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:317)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:154)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:143)
    at org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:145)
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java)
    at android.os.Handler.$$robo$$enqueueMessage(Handler.java:661)
    at android.os.Handler.enqueueMessage(Handler.java)
    at android.os.Handler.$$robo$$sendMessageAtTime(Handler.java:630)
    at android.os.Handler.sendMessageAtTime(Handler.java)
    at android.os.Handler.$$robo$$sendMessageDelayed(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java)
    at android.os.Handler.$$robo$$post(Handler.java:356)
    at android.os.Handler.post(Handler.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$scheduleCommit(FragmentManager.java:2098)
    at android.support.v4.app.FragmentManagerImpl.scheduleCommit(FragmentManager.java)
    at android.support.v4.app.FragmentManagerImpl.$$robo$$enqueueAction(FragmentManager.java:2081)
    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java)
    at android.support.v4.app.BackStackRecord.$$robo$$commitInternal(BackStackRecord.java:680)
    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java)
    at android.support.v4.app.BackStackRecord.$$robo$$commit(BackStackRecord.java:634)
    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java)
    at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragmentTest.setUp(InsightsFragmentTest.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:16)
    at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
    Caused by: android.content.res.Resources$NotFoundException: null
    Caused by: android.content.res.Resources$NotFoundException: File jar:/Users/philips/.m2/repository/org/robolectric/android-all/o-preview-4-robolectric-0/android-all-o-preview-4-robolectric-0.jar!/res/drawable/progress_medium_material.xml from drawable resource ID #0x108091c
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:769)
    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:600)
    at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
    at org.robolectric.internal.bytecode.ShadowImpl.directlyOn(ShadowImpl.java:59)
    at org.robolectric.shadow.api.Shadow.directlyOn(Shadow.java:57)
    at org.robolectric.shadows.ShadowResourcesImpl.loadDrawable(ShadowResourcesImpl.java:238)
    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java)
    at android.content.res.Resources.loadDrawable(Resources.java:885)
    at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
    at android.widget.ProgressBar.__constructor__(ProgressBar.java:281)
    at android.widget.ProgressBar.<init>(ProgressBar.java)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:164)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:148)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragment.onCreateView(InsightsFragment.java:73)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
    at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:164)
    at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:31)
    at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:138)
    at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:317)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:154)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:143)
    at org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:145)
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java)
    at android.os.Handler.enqueueMessage(Handler.java:661)
    at android.os.Handler.sendMessageAtTime(Handler.java:630)
    at android.os.Handler.sendMessageDelayed(Handler.java:600)
    at android.os.Handler.post(Handler.java:356)
    at android.support.v4.app.FragmentManagerImpl.scheduleCommit(FragmentManager.java:2098)
    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2081)
    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:680)
    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:634)
    at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragmentTest.setUp(InsightsFragmentTest.java:66)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:16)
    at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

0 个答案:

没有答案