Android测试BuildConfig字段 [英] Android tests BuildConfig field
问题描述
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 inBuildConfig
: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 forandroidTest
(the one that is created inapp/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屋!