我想设置 .apk 文件,这些文件将用于使用 SpoonGradlePlugin 运行我的测试。
我可以从 gradle 文件中以编程方式设置可用的属性:
但是我的项目有各种风格和名称,我想测试它们。使用当前设置,我得到:
* What went wrong:
A problem was found with the configuration of task ':app:spoonDebugAndroidTest'.
> File '/Users/F1sherKK/Dev/MyApp-Android/app/build/outputs/apk/app-debug.apk' specified for property 'applicationApk' does not exist.
我的构建名称是:
app-debug-androidTest-unaligned.apk
MyApp-debugA-1.2.3-201.apk
MyApp-debugB-1.2.3-201.apk
MyApp-debugC-1.2.3-201.apk
这就是为什么我想在 gradle 代码或控制台中的某个地方设置我的 .apk。到目前为止,我发现 Spoon Gradle Plugin 中有可用的字段:
有名字:
/** Instrumentation APK. */
@InputFile
File instrumentationApk
/** Application APK. */
@InputFile
File applicationApk
但是我无法访问像 SpoonExtension.groovy 中的 gradle 这样的属性。
有没有办法设置这些字段?
//编辑 - 添加了一些尝试:这是我的基本勺子配置:
spoon {
debug = true
baseOutputDir = file("$buildDir/spoon-log")
if (project.hasProperty('spoonClassName')) {
className = project.spoonClassName
if (project.hasProperty('spoonMethodName')) {
methodName = project.spoonMethodName
}
}
}
以及扩展它并覆盖 instumentationArgs 以设置包和启动其他类型的测试的任务。
task spoonAllTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
instrumentationArgs = ["package=com.myapp.sendmoney.instrumentation"]
}
}
task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
instrumentationArgs = ["package=com.myapp.instrumentation.flowtests"]
}
}
现在我尝试编辑 applicationApk 或 instrumentationApk 文件:
Edit2:我尝试了新事物:
task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
spoon {
inputs.property("applicationApk", "$buildDir/outputs/apk/ap12345p-debug.apk")
inputs.property("instrumentationApk", "$buildDir/outputs/apk/ap125p-debug.apk")
println inputs.getFiles()
println inputs.getProperties()
instrumentationArgs = ["package=com.azimo.sendmoney.instrumentation.flowtests"]
}
}
和终端响应:
2015-10-26 20:24:12 [SR.runTests] Executing instrumentation suite on 0 device(s).
2015-10-26 20:24:12 [SR.runTests] Application: com.azimo.sendmoney.debug1 from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug.apk
2015-10-26 20:24:12 [SR.runTests] Instrumentation: com.azimo.sendmoney.debug1.test from /Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
:app:spoon
:app:spoonFlowTests
file collection
{instrumentationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap125p-debug.apk, applicationApk=/Users/F1sherKK/Dev/Azimo-Android/app/build/outputs/apk/ap12345p-debug.apk}
:Azimo-Android:app:help
Welcome to Gradle 2.5.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see a list of command-line options, run gradlew --help
To see more detail about a task, run gradlew help --task <task>
BUILD SUCCESSFUL
Total time: 13.289 secs