我想要一种将命令行参数发送到我的测试类以运行所有单元测试并从中创建测试覆盖率报告的方法。我使用下面的命令来生成测试覆盖率报告并传递参数
./gradlew createDebugCoverageReport -Dparam=input1
Run Code Online (Sandbox Code Playgroud)
下面是应用程序 gradle 文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.testcoverageapp"
minSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
testOptions {
unitTests.includeAndroidResources = true
unitTests.all {
useJUnitPlatform()
test {
println systemProperties['param']
systemProperties(System.getProperties())
}
}
}
tasks.withType(Test){
systemProperties=System.properties
println systemProperties['param.name']
systemProperty 'param.name', System.getProperty('param')
}
}
dependencies {
implementation fileTree(dir: …Run Code Online (Sandbox Code Playgroud) android gradle android-testing build.gradle android-instrumentation