Android tests BuildConfig field

♀尐吖头ヾ 提交于 2019-12-19 02:38:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40156906/android-tests-buildconfig-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!