首页 > 解决方案 > 未解决的参考:isFalse of truth library android with kotlin

问题描述

我是 android 单元测试的新手。我添加了最新的谷歌真相库,但是当我尝试使用它时它仍然没有导入包。几个小时后,它突然奇迹般地开始工作了,我不知道是怎么回事。

然后我创建了另一个测试类,但在这个类中,我收到错误未解析的引用:isFalse,它在以前的测试类中工作得非常好。

所有依赖项:

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
    applicationId "com.example.android.unittestgithubpro"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

//Tests
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation "com.google.truth:truth:1.1.2"
androidTestImplementation "com.google.truth.truth:1.1.2"

// testImplementation "com.google.truth.extensions:truth-java8-extension:1.1.2"

}

运行良好的测试类: TestClass1

显示错误的测试类: TestClass2

我什至尝试过清理、重建项目并使缓存无效并重新启动。但没有收获。

现在我得到以下错误:

FAILURE: Build failed with an exception.

无法解析配置“:app:debugAndroidTestRuntimeClasspath”的所有文件。找不到 com.google.truth.truth:1.1.2:。要求:项目:app

在此处输入图像描述

标签: androidunit-testingkotlingoogle-truth

解决方案


推荐阅读