You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启用ANDROIDX_TEST_ORCHESTRATOR 1.4.0时提示找不到测试如何解决?

问题现象

使用androidx.test:orchestrator:1.4.0版本时,启用如下配置后执行测试报错com.android.build.gradle.internal.testing.ConnectedDevice > No tests found.[GM1910 - 11] FAILED:

testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
}

已确认1.4.0版本不存在1.2.0及以下版本的同类已知问题,提前手动安装了orchestrator、test-services的对应版本apk后,手动执行测试命令仍返回0条用例执行。

排查&解决步骤
  • 检查测试用例归属和注解:确认待执行测试放在androidTest目录下,测试类标注@RunWith(AndroidJUnit4::class)(Kotlin)/@RunWith(AndroidJUnit4.class)(Java),测试方法标注@org.junit.Test注解,没有误导入其他同名Test注解。
  • 移除手动安装的测试服务apk:执行adb uninstall androidx.test.orchestrator、adb uninstall androidx.test.services,不要手动管理这两个apk的安装,交由Gradle自动部署,避免版本不匹配。
  • 补全Gradle依赖配置:必须同时声明orchestrator和test-services的依赖,示例配置如下:
android {
    namespace "com.example.notroid" // 替换为你的应用包名
    defaultConfig {
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
    }

    buildTypes {
        debug {
            // 测试变体关闭混淆和资源压缩,避免测试类被裁剪
            minifyEnabled false
            shrinkResources false
        }
    }
}

dependencies {
    // 基础测试依赖
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    // 测试编排相关依赖
    androidTestUtil 'androidx.test:orchestrator:1.4.0'
    androidTestUtil 'androidx.test:services:1.4.0'
}
  • 确认instrumentation配置匹配:如果你的应用配置了applicationIdSuffix、多渠道打包等修改包名的配置,需要同步修改testInstrumentationRunner对应的目标包名,确保和应用实际运行的包名一致,不要硬编码写死。
  • 清理缓存后重试:执行./gradlew clean后重新执行./gradlew connectedAndroidTest运行测试即可。

内容的提问来源于stack exchange,提问作者pvd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 15:48:03