android - 为 Spoon Gradle Plugin 设置 applicationApk 和 instrumentationApk

标签 android groovy gradle spoon android-instrumentation

我想设置 .apk 文件,这些文件将用于使用 SpoonGradlePlugin 运行我的测试。

我可以从 gradle 文件中以编程方式设置可用属性:

https://github.com/stanfy/spoon-gradle-plugin/blob/master/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy

但我的项目有各种风格和名称,我想测试它们。使用当前设置,我得到:

* 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 中有可用的字段:

https://github.com/stanfy/spoon-gradle-plugin/blob/master/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy

名字:

  /** Instrumentation APK. */
  @InputFile
  File instrumentationApk

  /** Application APK. */
  @InputFile
  File applicationApk

但我无法访问 gradle 中的那些属性,例如 SpoonExtension.groovy 中的属性。

有什么方法可以设置这些字段吗?

//编辑 - 添加了一些尝试: 这是我的基本勺子配置:

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 文件:

enter image description here

enter image description here

enter image description here

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

最佳答案

您可以在更改apk名称后应用Spoon插件,如下所示:

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(
                    output.outputFile.parent,
                    output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
        }
    }
afterEvaluate {
        apply plugin: 'spoon'
        spoon {
            debug = true;
        }
    }

来源:https://github.com/stanfy/spoon-gradle-plugin/issues/70

关于android - 为 Spoon Gradle Plugin 设置 applicationApk 和 instrumentationApk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33285090/

相关文章:

android - GoogleApiClient : hide GPS icon on status bar when a service is in the background

java - getResources().getColor() 即使在 API 检查后也显示已弃用

groovy - 如何在 Groovy 中拦截此构造函数调用?

groovy - 如何使用 groovy 递归检查文件是否存在并重命名(如果存在)?

regex - 非匹配组的目的是什么

Android - 应用程序在 Pre-Lollipop 设备上崩溃

android - 如何在我的发布 aar 中打包多个 AAR

android - HashMap<String, Drawable> mDrawables;

java - Gradle:将 web-inf/libs 复制到 war 根目录

android - 在根项目上找不到属性 'android'