首页 > 解决方案 > Android Studio - 未解决的参考:真相

问题描述

我正在尝试在我的项目中包含 Google Truth 框架进行测试。我遵循了有关如何获取项目设置的文档。

这是来自我的应用程序的 build.gradle 文件:

dependencies {
    ...
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
    androidTestImplementation 'androidx.test.ext:truth:1.1.0'
    androidTestImplementation 'com.google.truth:truth:0.43'
}

同步过程成功完成。

然后我尝试运行本地单元测试,例如:

import org.junit.Test
import com.google.common.truth.Truth.*

class CustomExampleUnitTest {

    @Test
    fun testBlank_isCorrect() {
        assertThat("".isBlank()).isTrue()
    }
}

我收到 Kotlin 编译器错误:未解决的参考:真相

有几点需要注意:

因此,在完成上述步骤后,我尝试运行测试,但仍然遇到未解决的问题。

任何人都可以尝试对此有所了解吗?有没有人遇到过这种情况。我将非常感谢任何形式的帮助!

标签: google-truth

解决方案


如果您的测试在androidTest目录中,那么您需要

androidTestImplementation 'com.google.truth:truth:0.43'

但是如果您的测试在test目录中,那么您需要

testImplementation 'com.google.truth:truth:0.43'

推荐阅读