【发布时间】:2021-11-03 22:11:02
【问题描述】:
在像official documentation 这样为单元测试创建类之后,我导入了 com.google.common.truth.Truth.assertThat 和 org.junit.Test 库,但是android studio 无法获取并显示错误“无法解析符号“Truth””和“无法解析符号“测试””。
在搜索了解决此问题的方法后,我在 StackOverflow 上遇到了一个question,它询问了类似的问题。我做了那里推荐的所有事情,但我仍然无法导入这些类。
我的项目 build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
我的项目模块 build.gradle
dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
}
我的测试课
import com.google.common.truth.Truth.assertThat;
import org.junit.Test;
【问题讨论】:
-
您的测试在哪个文件夹中?
test还是androidTest? (他们应该在test)
标签: java android android-studio junit google-truth