【问题标题】:Junit version dependency in androidTest - can't use 4.13androidTest 中的 Junit 版本依赖项 - 无法使用 4.13
【发布时间】:2022-01-02 22:12:56
【问题描述】:

我正在将 androidTest 写入我的应用程序。应用程序使用 jetpack compose 和 hilt 进行依赖注入。为了设置测试,我需要为测试规则使用 order 参数,所以我需要使用 jUnit 4.13,但是当我尝试使用它们时,运行测试时出错:

What went wrong:

Execution failed for task ':app:processDebugAndroidTestManifest'.
> Could not resolve all files for configuration' :app:debugAndroidTestRuntimeClasspath'.
> Could not resolve junit:junit:4.13.2.

 Required by:
     project :app
     project :app > com.google.truth:truth:1.1.3
  > Cannot find a version of 'junit:junit' that satisfies the version constraints:
       Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
       Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'
> Could not resolve junit:junit:{strictly 4.12}.
 Required by:
     project :app
  > Cannot find a version of 'junit:junit' that satisfies the version constraints:
       Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
       Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'

> Could not resolve junit:junit:4.12.
 Required by:
     project :app > androidx.test.ext:junit:1.1.3
     project :app > androidx.compose.ui:ui-test-junit4:1.0.2
     project :app > androidx.arch.core:core-testing:2.1.0
     project :app > androidx.test:runner:1.4.0
  > Cannot find a version of 'junit:junit' that satisfies the version constraints:
       Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
       Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'

> Could not resolve junit:junit:4.13.
 Required by:
     project :app > com.google.dagger:hilt-android-testing:2.38.1
  > Cannot find a version of 'junit:junit' that satisfies the version constraints:
       Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
       Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
       Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
       Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'

我从另一个可以运行的项目中复制了我所有的 androidTest 依赖项......可能是其他的东西,但我找不到解决方案。

我找到了应该运行命令的地方:

./gradlew :app:dependencyInsight --dependency junit:junit --configuration debugAndroidTestRuntimeClasspath

但老实说,我不知道我能用输出做什么: https://pastebin.com/0F9Wt0mQ

我的 androidTest 依赖项是:

androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.2"
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.38.1'
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.38.1'
androidTestImplementation "junit:junit:4.13.2"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1"
androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
androidTestImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
androidTestImplementation "io.mockk:mockk-android:1.12.0"
androidTestImplementation 'androidx.test:runner:1.4.0'

我不确定还需要什么其他信息。

【问题讨论】:

    标签: android unit-testing junit android-jetpack-compose


    【解决方案1】:

    其实我找到了一个解决方案,但我不确定它是否正确。

    我已将依赖项更新为 alpha 版本:

    implementation 'androidx.test:runner:1.4.1-alpha02'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4-alpha02'
    androidTestImplementation 'androidx.test:core-ktx:1.4.1-alpha02'
    androidTestImplementation 'androidx.test:runner:1.4.1-alpha02'
    

    它开始工作了。实际上,在这个依赖项的 chengelog 中提到了 junit 4.13.2,但在我复制了未使用的依赖项 alpha 版本的项目中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-25
      • 2019-05-18
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 2017-02-10
      • 2021-07-25
      • 1970-01-01
      相关资源
      最近更新 更多