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

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

我正在为我的应用编写androidTest。应用使用jetpack compose和hilt进行依赖注入。为了设置测试,我需要使用测试规则的顺序参数,因此我需要使用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'

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

oo7oh9g9

oo7oh9g91#

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

android {
...
}

configurations.all {
    resolutionStrategy.force("junit:junit:4.13.2")
}

dependencies {
...
}
83qze16e

83qze16e2#

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

implementation 'androidx.test:runner:1.5.0-alpha04'
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版本的项目中,没有使用

相关问题