Java 自定义布局上的Robolectric单元测试ClassCastException

Java 自定义布局上的Robolectric单元测试ClassCastException,java,android,unit-testing,android-fragments,robolectric,Java,Android,Unit Testing,Android Fragments,Robolectric,当我在android应用程序上使用自定义布局或自定义组件测试活动或片段时,我在Robolectric单元测试中有“ClassCastException”。 例子: 扩展线性布局的视图。当我启动一个片段时,我得到一个错误: java.lang.ClassCastException:com.app.test.ui.view.CrumbView无法转换为com.app.test.ui.view.CrumbView 有人知道怎么修吗?或者它还没有被机器人分子所支持 java.lang.ClassCast

当我在android应用程序上使用自定义布局或自定义组件测试活动或片段时,我在Robolectric单元测试中有“ClassCastException”。 例子: 扩展线性布局的视图。当我启动一个片段时,我得到一个错误: java.lang.ClassCastException:com.app.test.ui.view.CrumbView无法转换为com.app.test.ui.view.CrumbView 有人知道怎么修吗?或者它还没有被机器人分子所支持

java.lang.ClassCastException: com.app.test.ui.view.DrawerView cannot be cast to com.app.test.ui.view.DrawerView

at com.app.test.ui.activity.equipements.EquipementsActivity.onCreate(EquipementsActivity.java:61)
at android.app.Activity.performCreate(Activity.java:6975)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
at org.robolectric.android.controller.ActivityController$1.run(ActivityController.java:58)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:364)
at org.robolectric.shadows.CoreShadowsAdapter$1.runPaused(CoreShadowsAdapter.java:26)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:55)
at org.robolectric.android.controller.ActivityController.create(ActivityController.java:65)
at com.app.test.ui.activity.equipements.EquipementsActivityTest.setUp(EquipementsActivityTest.java:24)
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.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:83)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1846)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:810)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:675)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
at org.powermock.classloading.AbstractClassloaderExecutor.getResult(AbstractClassloaderExecutor.java:76)
at org.powermock.classloading.AbstractClassloaderExecutor.invokeWithClassLoader(AbstractClassloaderExecutor.java:64)
at org.powermock.classloading.AbstractClassloaderExecutor.executeWithClassLoader(AbstractClassloaderExecutor.java:56)
at org.powermock.classloading.SingleClassloaderExecutor.execute(SingleClassloaderExecutor.java:33)
at org.powermock.classloading.AbstractClassloaderExecutor.execute(AbstractClassloaderExecutor.java:40)
at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:75)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:226)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:108)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:35)
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:62)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:149)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:141)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.java:132)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.java:141)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
onCreate(equipmentsactivity.java:61)的行指向: DrawerView-DrawerView=findviewbyd(R.id.drawer)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_equipements);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    DrawerView drawerView = findViewById(R.id.drawer);
    ActionBarDrawerToggle toggle .......
只需将“com.app.test.ui.view.”添加到@PowerMockIgnore即可进行单元测试。 例如: @PowerMockIgnore({“org.mockito.”,“org.roblectric.”,“android.”,“com.app.test.ui.view.*.})

只需将“com.app.test.ui.view.”添加到@PowerMockIgnore中进行单元测试。 例如:
@PowerMockIgnore({“org.mockito.”、“org.roblectric.”、“android.”、“com.app.test.ui.view.*”})

请添加更多关于您的问题以及您目前为解决问题所做努力的详细信息/代码,以便人们能够更好地帮助您。阅读请添加更多关于您的问题的详细信息/代码,以及您迄今为止为解决问题所做的努力,以便人们能够更好地帮助您。阅读为什么是-1?为我工作为什么是-1?为我工作