在遇到这个要点之后:https://gist.github.com/chemouna/00b10369eb1d5b00401b ,我注意到它正在使用 Google Truth
库:https://google.github.io/truth/ .因此,我开始按照以下过程将库添加到 Android Studio 中的 build.gradle
文件中:
buildscript {
repositories.mavenLocal()
}
dependencies {
testImplementation "com.google.truth:truth:0.40"
}
但是当我想为我的断言 java 类添加 Truth 入口点的静态导入时:
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
我收到无法解析符号 Truth
的错误。
我试图重建我的项目并实现此处所述的解决方案:AndroidTestCompile dependencies not recognized in the imports ,主要运行以下gradle任务:
- ./gradlew app:dependencies
- 组装Android测试
但问题依旧。
有什么帮助吗?
我真的应该在我的 build.gradle 文件中添加这些行吗? :
buildscript {
repositories.mavenLocal()
}
如果我已经有了这些:
repositories {
mavenCentral()
jcenter()
google()
}
最佳答案
To use the Java 8 extensions, also include com.google.truth.extensions:truth-java8-extension:0.40.
注意
您应该调用 androidTestImplementation
androidTestImplementation "com.google.truth:truth::0.40" // Latest version 1.1.3
阅读有关的更多信息Truth - Fluent assertions for Java .
关于安卓工作室 : Cannot resolve symbol "Truth" (Truth library),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50448004/