Class 未找到。未找到测试 class

Class not found. Test class not found

这是我的屏幕:

我应该设置什么设置? 如何避免弃用 class?

我想用espresso,然后尝试用UiAutomator,如何设置需要的必要设置?

我输了差不多一整天。

@RunWith(AndroidJUnit4::class)
@LargeTest
class MainActivityTest {

    @Rule
    @JvmField
    var activityTest = ActivityTestRule(MainActivity::class.java)

    fun c(){
        assertEquals(1,1)
    }
}

GRADLE

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.network"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13'

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'

    //okhttp library
    implementation("com.squareup.okhttp3:okhttp:4.7.2")
    // coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
    //gson
    implementation 'com.google.code.gson:gson:2.8.6'
    //recycler
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    //picasso
    implementation 'com.squareup.picasso:picasso:2.71828'
    //broadcast
    implementation 'com.android.support:design:26.1.0'
    //interceptor
    implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0'
}

您没有正确设置 test runner

这一行:

"android.support.test.runner.AndroidJUnitRunner"

应该改为:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

因为您正在使用新的 androidx 库而不是旧的 support 库。

没有这个你会得到这个 No tests were found 错误。不要忘记添加 testInstrumentationRunner 关键字。

并在 gradle 文件中将 junit 添加到 androidTestImplementation:

androidTestImplementation 'androidx.test.ext:junit:1.1.1'