安卓工作室 : Cannot resolve symbol "Truth" (Truth library)

标签 android testing android-espresso google-truth

在遇到这个要点之后: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/

相关文章:

安卓 4.2 单选按钮安卓 :drawableLeft bug?

android - 由于当前屏幕上的更新,防止 Flutter Provider 重建前一屏幕中的小部件

ruby - 我怎样才能对我的默认范围进行 rspec 测试

testing - DNF规范化测试用例 : break my code with your test case

android - 排除基于设备的测试

android - 使用 Espresso 在数据之前显示测试加载程序

java - 从我的DialogFragment中的MainActivity访问ArrayList <String>遇到麻烦

android - 从build.gradle(Module)中提取通用代码到顶层build.gradle(Project)

java - getTitle() 函数在 Selenium Web 驱动程序中返回不正确的结果

android - 谷歌 Espresso 或机器人