首页 > 解决方案 > Android 测试编排器未找到任何测试

问题描述

我正在使用 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'
        }
    }
}

有了这个

androidTestImplementation 'com.android.support.test:runner:1.1.1'
    androidTestUtil 'com.android.support.test:orchestrator:1.1.1'

这是 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)
    }
}

然后,在 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

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

标签: androidkotlininstrumented-testandroid-test-orchestrator

解决方案


推荐阅读