Android Studio Instrumentation 测试构建变体 [英] Android Studio Instrumentation testing build variant

查看:43
本文介绍了Android Studio Instrumentation 测试构建变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用自定义构建变体模拟编写仪器测试.在这个构建变体中,我模拟了我的类和服务器.当我自己尝试使用模拟构建时,它工作正常,但我似乎无法使用模拟构建进行测试.这是我在 Android Studio 中的配置.

So I am trying to write instrumentation tests using a custom build variant, mock. In this build variant I mocked up my classes and server. When I try using the mock build myself it works fine, but I can't seem to use my mock build for testing. Here's what my configuration looks like inside Android Studio.

我在运行测试时遇到了一些问题,因此我尝试卸载除模拟版本之外的所有应用版本,但我不断收到此错误:

I had some issues getting my tests to run so I tried to uninstall all versions of my app except my mock version and I keep getting this error:

测试运行开始测试运行失败:无法找到检测目标包:com.teamtreehouse.review.debug

Test running startedTest running failed: Unable to find instrumentation target package: com.teamtreehouse.review.debug

但是,当我尝试针对调试构建变体运行测试时,它运行良好.它会安装我的调试版本,然后继续运行测试.

However when I try to run my tests against the debug build variant it works fine. It installs my debug version then proceeds to run the tests.

推荐答案

可以对不同的构建变体进行测试;但只有一个.默认为调试.

You can do testing on a different build variant; but only on one. The default is debug.

看到这个:https://developer.android.com/studio/build/gradle-tips#change-the-test-build-type

目前只测试了一种构建类型.默认情况下它是调试构建类型,但可以通过以下方式重新配置:

Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:

android {
    ...
    testBuildType "staging"
}

这篇关于Android Studio Instrumentation 测试构建变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆