androidTest中的Junit版本依赖性-无法使用4.13

zf2sa74q  于 2022-11-11  发布在  Android
关注(0)|答案(2)|浏览(371)

我正在为我的应用编写androidTest。应用使用jetpack compose和hilt进行依赖注入。为了设置测试,我需要使用测试规则的顺序参数,因此我需要使用jUnit 4.13,但当我尝试使用它们时,我在运行测试时遇到错误:

  1. What went wrong:
  2. Execution failed for task ':app:processDebugAndroidTestManifest'.
  3. > Could not resolve all files for configuration' :app:debugAndroidTestRuntimeClasspath'.
  4. > Could not resolve junit:junit:4.13.2.
  5. Required by:
  6. project :app
  7. project :app > com.google.truth:truth:1.1.3
  8. > Cannot find a version of 'junit:junit' that satisfies the version constraints:
  9. Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
  10. Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
  11. Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
  12. Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
  13. Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
  14. Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
  15. Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
  16. Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'
  17. > Could not resolve junit:junit:{strictly 4.12}.
  18. Required by:
  19. project :app
  20. > Cannot find a version of 'junit:junit' that satisfies the version constraints:
  21. Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
  22. Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
  23. Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
  24. Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
  25. Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
  26. Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
  27. Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
  28. Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'
  29. > Could not resolve junit:junit:4.12.
  30. Required by:
  31. project :app > androidx.test.ext:junit:1.1.3
  32. project :app > androidx.compose.ui:ui-test-junit4:1.0.2
  33. project :app > androidx.arch.core:core-testing:2.1.0
  34. project :app > androidx.test:runner:1.4.0
  35. > Cannot find a version of 'junit:junit' that satisfies the version constraints:
  36. Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
  37. Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
  38. Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
  39. Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
  40. Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
  41. Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
  42. Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
  43. Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'
  44. > Could not resolve junit:junit:4.13.
  45. Required by:
  46. project :app > com.google.dagger:hilt-android-testing:2.38.1
  47. > Cannot find a version of 'junit:junit' that satisfies the version constraints:
  48. Dependency path 'Myapp:app:unspecified' --> 'junit:junit:4.13.2'
  49. Constraint path 'Myapp:app:unspecified' --> 'junit:junit:{strictly 4.12}' because of the following reason: debugRuntimeClasspath uses version 4.12
  50. Dependency path 'Myapp:app:unspecified' --> 'androidx.test.ext:junit:1.1.3' (runtime) --> 'junit:junit:4.12'
  51. Dependency path 'Myapp:app:unspecified' --> 'androidx.compose.ui:ui-test-junit4:1.0.2' (releaseVariantReleaseRuntimePublication) --> 'junit:junit:4.12'
  52. Dependency path 'Myapp:app:unspecified' --> 'com.google.dagger:hilt-android-testing:2.38.1' (runtime) --> 'junit:junit:4.13'
  53. Dependency path 'Myapp:app:unspecified' --> 'androidx.arch.core:core-testing:2.1.0' (runtime) --> 'junit:junit:4.12'
  54. Dependency path 'Myapp:app:unspecified' --> 'com.google.truth:truth:1.1.3' (runtime) --> 'junit:junit:4.13.2'
  55. Dependency path 'Myapp:app:unspecified' --> 'androidx.test:runner:1.4.0' (runtime) --> 'junit:junit:4.12'

我从它工作的另一个项目复制了我所有的androidTest依赖项,所以...可能是其他的东西,但我找不到解决方案。
我在某个地方找到了一个我应该运行的命令:

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

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

  1. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  2. androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
  3. androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.2"
  4. androidTestImplementation 'com.google.dagger:hilt-android-testing:2.38.1'
  5. kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.38.1'
  6. androidTestImplementation "junit:junit:4.13.2"
  7. androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1"
  8. androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
  9. androidTestImplementation "com.google.truth:truth:1.1.3"
  10. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  11. androidTestImplementation 'androidx.test:core-ktx:1.4.0'
  12. androidTestImplementation "io.mockk:mockk-android:1.12.0"
  13. androidTestImplementation 'androidx.test:runner:1.4.0'

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

oo7oh9g9

oo7oh9g91#

对我来说,将以下内容添加到模块的build.gradle文件中就可以了:

  1. android {
  2. ...
  3. }
  4. configurations.all {
  5. resolutionStrategy.force("junit:junit:4.13.2")
  6. }
  7. dependencies {
  8. ...
  9. }
83qze16e

83qze16e2#

事实上我找到了一个解决方案,但我不确定它是否正确。
我已将依赖项更新为alpha版本:

  1. implementation 'androidx.test:runner:1.5.0-alpha04'
  2. androidTestImplementation 'androidx.test.ext:junit:1.1.4-alpha02'
  3. androidTestImplementation 'androidx.test:core-ktx:1.4.1-alpha02'
  4. androidTestImplementation 'androidx.test:runner:1.4.1-alpha02'

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

相关问题