繁体   English   中英

由于 IncompatibleClassChangeError,Espresso 测试失败

[英]Espresso testing is failing due to IncompatibleClassChangeError

浓缩咖啡测试运行良好,但在尝试检查是否出现吐司消息时,使用此代码

onView(withText(R.string.added_successfully_msg)).inRoot(toastMatcher())
                .check(matches(withText(R.string.added_successfully_msg))); 

或者这个

onView(withText(R.string.added_successfully_msg)).inRoot(withDecorView(not(activity.getWindow().getDecorView()))).check(matches(isDisplayed()));

抛出此异常

java.lang.IncompatibleClassChangeError: Class 'org.hamcrest.StringDescription' does not implement interface 'java.lang.Iterable' in call to 'java.util.Iterator java.lang.Iterable.iterator()' (declaration of 'org.hamcrest.BaseDescription' appears in /data/app/my package name.test-7NCoDq2dIYza4GpnMXXGhQ==/base.apk)
at org.hamcrest.BaseDescription.appendValueList(BaseDescription.java:81)
at androidx.test.espresso.matcher.BoundedDiagnosingMatcher.describeTo(BoundedDiagnosingMatcher.java:4)
at org.hamcrest.BaseDescription.appendDescriptionOf(BaseDescription.java:24)
at org.hamcrest.StringDescription.toString(StringDescription.java:28)
at org.hamcrest.BaseMatcher.toString(BaseMatcher.java:26)
at java.util.Formatter$FormatSpecifier.printString(Formatter.java:2978)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2855)
at java.util.Formatter.format(Formatter.java:2524)
at java.util.Formatter.format(Formatter.java:2459)
at java.lang.String.format(String.java:2911)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:12)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

测试依赖

  testImplementation 'androidx.test:monitor:1.5.0'
    testImplementation 'junit:junit:4.13.2'
    testImplementation "org.mockito:mockito-core:3.12.4"
    // Core library
    androidTestImplementation 'androidx.test:core:1.4.0'
// AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.1-alpha06'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'

    // Espresso dependencies
    def espressoVersion = "3.5.0-alpha06"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
    androidTestImplementation ("androidx.test.espresso:espresso-contrib:$espressoVersion"){exclude module: 'protobuf-lite'}
    androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
    implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"

我认为当我使用withText()时会引发此异常,但我找不到解决方案。

感谢帮助

我也刚遇到这个。 我认为这可能是 espresso 3.5.0-alpha06 中的一个错误 - 如果我恢复到 3.5.0-alpha04 它会再次起作用

我还没有找到向谷歌提交的错误,但它可能值得做。

这可能是与另一个不兼容的库发生冲突,但我还无法确定确切的原因。

更新:似乎在上次更新 3.5.0-alpha07 中解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM