首页 > 解决方案 > Kotlin 单元测试无法解决任何问题

问题描述

我已经用 kotlin 构建了一个应用程序,一切正常,然后我进行了一些单元测试,IDE 没有显示错误,但是当我运行测试时,构建失败并说:

cannot access built-in declaration '' Ensure that you have a dependency on the Kotlin standard library

应用等级:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'

implementation "org.jetbrains.anko:anko:0.10.8"
implementation "org.jetbrains.anko:anko-design:0.10.8"

implementation "org.jetbrains.anko:anko-recyclerview-v7:0.10.8"
implementation "org.jetbrains.anko:anko-recyclerview-v7-coroutines:0.10.8"
implementation "org.jetbrains.anko:anko-sqlite:0.10.8"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
//noinspection LifecycleAnnotationProcessorWithJava8
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.okhttp3:okhttp:3.14.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'

implementation 'net.sourceforge.streamsupport:streamsupport:1.7.0'

testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-inline:2.27.0"
testImplementation 'org.mockito:mockito-core:2.27.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

项目等级:

buildscript {
ext.kotlin_version = '1.3.41'
repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}}

标签: javaandroidunit-testingtestingkotlin

解决方案


推荐阅读