5

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
F1sher
  • 7,140
  • 11
  • 48
  • 85

4 Answers4

5

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

riwnodennyk
  • 8,140
  • 4
  • 35
  • 37
  • This will ignore your spoon custom settings like debug = true. See issue https://github.com/stanfy/spoon-gradle-plugin/issues/94 – Carlo Matulessy Jan 17 '17 at 08:09
0

We need to consider the annotation of the parameters:

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

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

Since they are marked as @InputFile, we should be able to create a custom task which depends on the Spoon one that passes the inputs using the input.files property.

A rough example (untested):

task customSpoon(type: Exec, dependsOn: spoon) {
     inputs.files ["path/instrumentation.apk", "path/debuggable.apk"]
}  

UPDATE

As an alternative, simply create a custom task which simulate a commandline parametrized call to the base Spoon task, like the following

task runSpoonTask(type: Exec) {
    commandLine './gradlew', 'spoon', '$buildDir/outputs/apk/ap12345p-debug.apk', '$buildDir/outputs/apk/ap125p-debug.apk'
}
bonnyz
  • 13,458
  • 5
  • 46
  • 70
  • Could I ask you to look at it a bit more closely? I've been fighting with it few days. Tried Inputs.getProperties(), InputFiles.getProperties() - too look for property name I could set, applicationApk = file('myfile'), apk and test-apk, Application and more. Also wrote email to creator of plugin but no response. Always get something like: No such property: applicationApk for class: com.stanfy.spoon.gradle.SpoonExtension_Decorated – F1sher Oct 26 '15 at 16:03
  • @F1sher Did you tried to create a new task which depends on the base spoon task as I suggested? Update your answer with your best try, I'll take a look – bonnyz Oct 26 '15 at 16:07
  • sorry I tried to reproduce as much as I remember from things I have tried and launch it, I did much more variations etc. I couldn't make stack format my code... don't know why so I gave you screens. – F1sher Oct 26 '15 at 16:53
  • @F1sher Did you tried...exactly the code I suggested? (you may just need to set the proper paths) – bonnyz Oct 26 '15 at 18:38
  • Yes. When I set your code then "inputs" is grey and when I put my cursor over it I get: Cannot resolve symbol 'inputs'. And in terminal after I launch it I can see this + path is 100% right: A problem occurred evaluating project ':app'. > No signature of method: org.gradle.api.internal.file.UnionFileCollection.getAt() is applicable for argument types: (java.util.ArrayList) values: [[/Users/F1sherKK/Dev/myApp/app/build/outputs/apk/app-debug.apk, ...]] Possible solutions: getAt(int), getAt(java.lang.String), putAt(java.lang.String, java.lang.Object), wait(), getAsPath(), last() – F1sher Oct 26 '15 at 19:06
  • I've added another edit. I managed to add some files but as u can see in outcome he still uses default ones and this "collection" that I created is ignored hmm... – F1sher Oct 26 '15 at 19:27
  • @F1sher The official docs is really obscure on this. I've added an alternative to my original answer, much simpler but a bit less serious ;) – bonnyz Oct 27 '15 at 18:48
0

Please see my answer to your different question explaining what is wrong with how you configure your tasks.

Community
  • 1
  • 1
Roman Mazur
  • 3,084
  • 1
  • 20
  • 24
0

I had the same problem:

... specified for property 'applicationApk' does not exist

We used this to rename from "app-debug.apk" to "currentProject-debug.apk":

applicationVariants.all { variant ->
            variant.outputs.each { output ->
                output.outputFile = new File(
                        output.outputFile.parent,
                        output.outputFile.name.replace("app", "${project.hdmiAppName}"))

            }
} 

But it seems that this works much better with Spoon:

defaultConfig {
    applicationId packageName
    ...
    setProperty("archivesBaseName", "${project.hdmiAppName}")
}

This will rename the "app"-Part of the APK-Name to whatever you like. In our case we have "${project.hdmiAppName}" specified in a properties-file. But i guess it can also be "MyApp-${versionName}".

StefanTo
  • 971
  • 1
  • 10
  • 28