Android测试BuildConfig字段 [英] Android tests BuildConfig field

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

问题描述

假设我的 build.gradle 文件为在 BuildConfig 中定义的相同变量定义了不同的值:
$ $ p $
$ def $ INT $ =
release {
buildConfigField BOOLEAN,VARIABLE,1
}

debug {
buildConfigField BOOLEAN,VARIABLE,2
}


$ / code $ / pre

我想定义对于 androidTest (在 app / build / generated / source / buildConfig /中创建的那个变量),此变量的BuildConfig androidTest / debug / {app_id} /test/BuildConfig.java



现在,该值与 debug 闭包。


是否可以更改它?
blockquote>

解决方案

我找到了一种方法来做到这一点 here
$ b 创建另一个 buildType (其名称不得以: test 开头),并将其名称传递给属性:

  android {

testBuildTypestaging
$ b $ def INTEGER =integer
def VARIABLE =variable
buildTypes {

debug {
buildConfigField BOOLEAN,VARIABLE,2
}

staging {
initWith(buildTypes .debug)
buildConfigField BOOLEAN,VARIABLE,4
}
}
}

测试必须针对 staging buildType


Suppose my build.gradle file defines different values for the same variable that is defined in BuildConfig:

android {
    def INTEGER= "integer"
    def VARIABLE = "variable"
    buildTypes {
        release {
            buildConfigField BOOLEAN, VARIABLE, "1"
        }

        debug {
            buildConfigField BOOLEAN, VARIABLE, "2"
        }
    }
}

I would like to define BuildConfig value for this variable for androidTest (the one that is created in app/build/generated/source/buildConfig/androidTest/debug/{app_id}/test/BuildConfig.java)

Now, the value is the same as in debug closure.

Is it possible to change it?

解决方案

I found a way to do this here

Create another buildType (whose name must not start with: test) and pass it's name to property:

android {

    testBuildType "staging"

    def INTEGER= "integer"
    def VARIABLE = "variable"
    buildTypes {

        debug {
            buildConfigField BOOLEAN, VARIABLE, "2"
        }

        staging {
            initWith(buildTypes.debug)
            buildConfigField BOOLEAN, VARIABLE, "4"
        }
    }
}

Tests must be run against staging buildType.

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

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