Android Field BuildConfig Testing

Suppose my file build.gradledefines 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 a value BuildConfigfor this variable for androidTest(the one created in app/build/generated/source/buildConfig/androidTest/debug/{app_id}/test/BuildConfig.java)

Now this value is the same as closing debug.

Is it possible to change it?

+4
source share
1 answer

I found a way to do it here

Create another one buildType(whose name should not begin with:) testand pass its name to the 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 should be performed against staging buildType.

+4

Source: https://habr.com/ru/post/1658333/


All Articles