Android 测试编排器未找到测试

Wai*_*ein 6 android kotlin instrumented-test android-test-orchestrator

我正在使用 Kotlin 编程语言开发 Android 应用程序。我正在为我的应用程序编写仪器测试。我还使用测试协调器来运行我的仪器测试。但是安装测试编排器并修改Grandle文件后,我无法在Android Studio中运行测试。

我将以下配置添加到 app.grandle 文件中

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.memento"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunner "com.example.memento.MockTestRunner"
        // Cleared between tests.
        testInstrumentationRunnerArguments clearPackageData: 'true'
        testOptions {
            execution 'ANDROID_TEST_ORCHESTRATOR'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有了这个

androidTestImplementation 'com.android.support.test:runner:1.1.1'
    androidTestUtil 'com.android.support.test:orchestrator:1.1.1'
Run Code Online (Sandbox Code Playgroud)

这是 MockTestRunner 类

导入 android.app.Application 导入 android.content.Context 导入 androidx.test.runner.AndroidJUnitRunner 导入 com.example.utils.MockApplicationController

class MockTestRunner: AndroidJUnitRunner()
{
    override fun newApplication(
        cl: ClassLoader?,
        className: String?,
        context: Context?
    ): Application {
        return super.newApplication(cl, MockApplicationController::class.java!!.getName(), context)
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,在Android Studio中,我尝试通过右键单击代码来运行测试,如下所示。 在此输入图像描述

这是我运行测试时得到的结果。

$ adb shell CLASSPATH=$(pm path android.support.test.services) app_process / android.support.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.example.memento.test/com.example.memento.MockTestRunner   -e debug false -e class 'com.example.memento.EventListTest#eventListIndexZeroTabRendersCurrentEvents' -e clearPackageData true android.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator
Waiting for process to come online...

Started running tests
Test running failed: No test results
Run Code Online (Sandbox Code Playgroud)

从字面上看,没有运行测试。我的配置有什么问题以及如何修复它。如果我删除测试协调器安装,我可以运行测试并且它按预期工作。