Unit testing 无法导入kotlin.test以使用assertFailsWith

Unit testing 无法导入kotlin.test以使用assertFailsWith,unit-testing,android-studio,kotlin,Unit Testing,Android Studio,Kotlin,对于我的单元测试,我需要导入kotlin.test以便能够使用assertFailsWith 我相信我的app build.grade文件中有正确的文件。文件的一部分是: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' dependencies { implementation fileTree(dir: '

对于我的单元测试,我需要导入kotlin.test以便能够使用assertFailsWith

我相信我的app build.grade文件中有正确的文件。文件的一部分是:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    // ----
    // Per https://developer.android.com/training/testing/unit-testing/local-unit-tests
    //
    // Required -- JUnit 4 framework
    testImplementation 'junit:junit:4.12'
    // Optional -- Robolectric environment
    testImplementation 'androidx.test:core:1.0.0'
    // Optional -- Mockito framework
    testImplementation 'org.mockito:mockito-core:1.10.19'
    // ----


    testImplementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
    testImplementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
}

我不确定我遗漏了什么…

对于Android项目和JUnit测试,您需要使用该模块,而不是
kotlin测试公共
kotlin测试注释公共
——这些适用于多平台项目中平台间共享的代码,在JVM/Android模块中被忽略

将这两个依赖项替换为此依赖项:

testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"