You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更新Android库后kotlin.test.BeforeTest无法解析,需添加什么依赖?

解决@BeforeTest无法解析的依赖问题

你代码里的@BeforeTest属于Kotlin标准测试库,需要在项目依赖中添加对应库才能正常解析。

根据你使用的Gradle配置类型,添加以下依赖:

Groovy DSL(build.gradle)

// 本地单元测试
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
// 设备仪器化测试
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

Kotlin DSL(build.gradle.kts)

// 本地单元测试
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
// 设备仪器化测试
androidTestImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")

注意替换$kotlin_version(或$kotlinVersion)为你项目实际使用的Kotlin版本号,确保和项目的Kotlin插件版本一致。

同时确认导入语句保持正确:

import kotlin.test.BeforeTest

内容的提问来源于stack exchange,提问作者CoolMind

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:24:49