Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set applicationApk and instrumentationApk for Spoon Gradle Plugin

I'd like to set .apk files that will be used to run my tests with SpoonGradlePlugin.

There are available properties I can set programatically from gradle file:

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

But my project has various flavours and names and I'd like to test them. With current setup I get:

* 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.

My build names are:

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

That's why I would like to setup my .apk somewhere in gradle code - or console. What I found so far there are fields available in Spoon Gradle Plugin there:

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

with names:

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

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

But I can't access those in gradle like properties in SpoonExtension.groovy.

Is there any way to setup those fields?

//EDIT - Added some tries: This is my base spoon config:

spoon {
    debug = true
    baseOutputDir = file("$buildDir/spoon-log")
    if (project.hasProperty('spoonClassName')) {
        className = project.spoonClassName

        if (project.hasProperty('spoonMethodName')) {
            methodName = project.spoonMethodName
        }
    }
}

And tasks extending it and overwriting instumentationArgs to set package and launch other kind of tests.

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"]
    }
}

And now I try to edit applicationApk or instrumentationApk file:

enter image description here

enter image description here

enter image description here

Edit2: I tried new thing:

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"]
    }
}

And the terminal response:

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
like image 524
F1sher Avatar asked Sep 27 '22 10:09

F1sher


1 Answers

You may apply the Spoon plugin after changing the apk name as following:

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;
        }
    }

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

like image 172
riwnodennyk Avatar answered Sep 28 '22 23:09

riwnodennyk