Android Studio -> Preferences... -> Plugins
,检查是否启用了测试插件(如JUnit)。File > Project Structure... > Project
,更新到最新的 Gradle 版本。build.gradle
(项目级别)中检查您是否正在使用最新版本。classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
在您的 build.gradle (模块级别)中
android {
...
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dependencies {
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
...
移除JUnit组排除
在同一个文件中,如果存在,则移除以下排除项:
exclude group: "org.junit.platform" //remove this line