Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android tests BuildConfig field

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?

like image 646
R. Zagórski Avatar asked Oct 20 '16 14:10

R. Zagórski


1 Answers

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.

like image 92
R. Zagórski Avatar answered Sep 21 '22 22:09

R. Zagórski