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

升级espresso-contrib至3.3.0以上版本导致构建失败求助

问题:升级Espresso-contrib至3.4.0+后Instrumentation测试无测试用例被找到导致构建失败

我们配置androidTestImplementation("androidx.test.espresso:espresso-contrib:3.3.0")时,Instrumentation测试可正常运行。但升级至3.4.0或3.5.0等新版本时,出现以下构建失败错误:

Instrumentation did not complete:
Instrumentation code: 0
Instrumentation result bundle: 

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDevShortTimeoutDebugAndroidTest'.
> There were failing tests. See the report at: 

测试报告显示无测试用例被找到。当前使用的androidTestImplementation依赖如下:

androidTestImplementation(project(":sharedTest"))
androidTestImplementation("androidx.test:core-ktx:1.5.0")
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("androidx.test:runner:1.5.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.4")
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.3.0")
androidTestImplementation("com.microsoft.appcenter:espresso-test-extension:1.5")
androidTestImplementation("org.mockito:mockito-android:$mockitoTestVersion")
androidTestImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
androidTestUtil("androidx.test:orchestrator:1.4.2")

解决思路与方案

  • 统一Espresso依赖版本:当前espresso-core为3.5.0,但espresso-contrib仍停留在3.3.0,版本不一致会引发兼容性问题。将espresso-contrib升级至3.5.0,与核心库版本对齐:

    androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.0")
    
  • 验证测试类配置:确保测试类放置在androidTest目录下,类上标注正确的运行注解(如@RunWith(AndroidJUnit4::class)),测试方法添加@Test注解,避免因注解缺失导致测试用例未被识别。

  • 同步Orchestrator版本:当前orchestrator版本为1.4.2,与androidx.test:runner:1.5.0存在版本不匹配风险,升级至1.5.0:

    androidTestUtil("androidx.test:orchestrator:1.5.0")
    
  • 排查第三方扩展冲突:com.microsoft.appcenter:espresso-test-extension:1.5版本较旧,可能与新版Espresso不兼容。尝试升级该依赖至最新版本,或暂时移除后重新运行测试,确认是否为冲突根源。

  • 清理构建缓存:执行./gradlew clean清除旧构建缓存,再重新执行测试任务,避免缓存导致的依赖加载异常。

  • 检查测试过滤规则:检查build.gradle中是否存在错误的测试过滤配置,确保没有意外排除所有测试类的规则。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 17:40:45