【问题标题】:Instrumentation test fails after updating libraries更新库后检测测试失败
【发布时间】:2019-11-20 00:27:54
【问题描述】:

我的所有仪器测试都有这些 gradle 依赖项:

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
    androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'

    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
    implementation 'androidx.fragment:fragment:1.1.0-alpha01'
    androidTestImplementation 'org.mockito:mockito-android:2.24.5'

一旦我将它们更新为:

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
    androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'

    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
    implementation 'androidx.fragment:fragment:1.2.0-alpha01'
    androidTestImplementation 'org.mockito:mockito-android:2.24.5'

然后运行测试,我得到以下错误:

找不到满足以下要求的“androidx.test:core”版本 版本限制:

依赖路径 'my_package_name:app:unspecified' --> 'androidx.test.espresso:espresso-intents:3.2.0' --> 'androidx.test:core:1.2.0'

....等等有很多行

我该如何解决这个问题?为什么会这样?

【问题讨论】:

    标签: android-gradle-plugin android-espresso


    【解决方案1】:

    为什么会这样?

    这是因为androidx.test:core:1.2.0 的版本冲突:

    依赖androidx.test.espresso:espresso-intents:3.2.0 使用1.2.0 版本的核心库。虽然还有另一个依赖项使用了同一库的另一个版本,这让 Gradle 很不高兴。如果您继续阅读那些 很多行,您会看到这个 另一个依赖项 是什么,但我高度怀疑它是 androidx.fragment:fragment-testing:1.2.0-alpha01,它取决于核心的 1.1.1 版本图书馆。

    如何解决这个问题:

    鉴于您确实需要升级您的 espresso,并假设有问题的库是片段测试,一个简单的解决方法是更改​​

    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-alpha01'
    

    debugImplementation ("androidx.fragment:fragment-testing:1.2.0-alpha01", {exclude group: 'androidx.test', module: 'core' })
    

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 1970-01-01
      • 2019-12-28
      • 2016-11-30
      • 2022-06-30
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多