【问题标题】:Android Studio Instrumentation testing build variantAndroid Studio Instrumentation 测试构建变体
【发布时间】:2015-09-09 16:35:53
【问题描述】:

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

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

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

但是,当我尝试针对调试构建变体运行测试时,它工作正常。它会安装我的调试版本,然后继续运行测试。

【问题讨论】:

    标签: android-studio android-testing android-espresso android-instrumentation


    【解决方案1】:

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

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

    目前只测试了一种构建类型。默认是调试 构建类型,但这可以重新配置:

    android {
        ...
        testBuildType "staging"
    }
    

    【讨论】:

    【解决方案2】:

    或者,您可以按照以下方式配置您的 testBuildType,以便您可以决定运行 androidTest 的任何构建类型,从命令行指定相应的属性。

    android {   
        ...
    
        if (project.hasProperty('androidTestRelease')) {
            testBuildType 'release'
        } else if (project.hasProperty('androidTestStaging')) {
            testBuildType 'staging'
        } else {
            testBuildType 'debug'
        }
        ...
    }
    

    从命令行

    ./gradlew connectedCheck -PandroidTestStaging 
    

    【讨论】:

      【解决方案3】:

      AFAIK androidTest 仅适用于调试 buildType。

      你可以使用构建风格来做你想做的事,一个很好的例子可以在这里找到:https://www.code-labs.io/codelabs/android-testing/#0

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-28
        • 2015-08-04
        • 2019-10-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多