java.lang.ClassCastException: android.os.Looper 不能转换为 org.robolectric.internal.bytecode.ShadowedObject

问题描述

我正在尝试使用带有勺子和 falcon-spoon 的 espresso 为我的应用程序自动截取 Android 测试应用程序成功启动并成功截取一个屏幕截图之后当我尝试使用 onView(withId( buttonId)).perform(click()) 它抛出以下异常。 我尝试降级依赖版本并更改 android-sdk 没有结果。

这里是抛出的异常。

java.lang.classCastException: android.os.Looper cannot be cast to org.robolectric.internal.bytecode.Shadowedobject
at org.robolectric.internal.bytecode.ShadowImpl.extract(ShadowImpl.java:14)
at org.robolectric.shadow.api.Shadow.extract(Shadow.java:25)
at org.robolectric.shadows.ShadowLooper.shadowLooper(ShadowLooper.java:39)
at org.robolectric.shadows.ShadowLooper.shadowMainLooper(ShadowLooper.java:50)
at org.robolectric.android.internal.LocalControlledLooper.drainMainThreadUntilIdle(LocalControlledLooper.java:15)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:99)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:43)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:94)
at com.dexcom.app.utils.CommonViewsHelperKt.clickNextButton(CommonViewsHelper.kt:43)
at com.dexcom.app.screen_crawler.SetupWizardScreenshots.setupWizardScreenShots(SetupWizardScreenshots.kt:49)
at java.lang.reflect.Method.invoke(Native Method)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:130)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runchild(BlockJUnit4ClassRunner.java:57)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runchild(Suite.java:128)
at org.junit.runners.Suite.runchild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2218)

这是我用于勺子和浓缩咖啡的 gradle 依赖项:

dependencies {

androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
androidTestImplementation "androidx.test:rules:1.3.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT"
androidTestImplementation "com.jraska:falcon:2.1.1"
androidTestImplementation "com.jraska:falcon-spoon-compat:2.1.1"
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)