Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Install extra APKs if received ( useful for Orchestrator ) (#159)
Browse files Browse the repository at this point in the history
Now that we allow to use Orchestrator it would be nice to install the APKs required by Orchestrator to run.
Instead of being specific for Orchestrator this PR allows devs to install any extra APK they need.

~~There are no tests or documentation written yet because I want to validate the approach taken first, if it's ok I'll update the docs and add some tests ( suggestions on which ones are welcomed )~~
  • Loading branch information
CristianGM authored and artem-zinnatullin committed Oct 30, 2018
1 parent d200b1c commit 984b64f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ Composer shipped as jar, to run it you need JVM 1.8+: `java -jar composer-latest
* Requires test orchestrator & test services APKs to be installed on device before executing.
* More info: https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator
* Example: `--with-orchestrator true`
* `--extra-apks`
* Apks to be installed for utilities. What you would typically declare in gradle as `androidTestUtil`
* Default: empty, only apk and test apk would be installed.
* Works great with Orchestrator to install orchestrator & test services APKs.
* Example: `--extra-apks path/to/apk/first.apk path/to/apk/second.apk`

##### Example

Expand Down
13 changes: 11 additions & 2 deletions composer/src/main/kotlin/com/gojuno/composer/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ data class Args(
description = "Either `true` or `false` to enable/disable running tests via Android Test Orchestrator. False by default.",
order = 12
)
var runWithOrchestrator: Boolean = false
var runWithOrchestrator: Boolean = false,

@Parameter(
names = arrayOf("--extra-apks"),
required = false,
variableArity = true,
description = "Extra APKs you would usually put on androidTestUtil",
order = 13
)
var extraApks: List<String> = emptyList()
)

// No way to share array both for runtime and annotation without reflection.
Expand All @@ -141,4 +150,4 @@ fun parseArgs(rawArgs: Array<String>) = Args().also { args ->

private class InstrumentationArgumentsConverter : IStringConverter<List<String>> {
override fun convert(argument: String): List<String> = listOf(argument)
}
}
6 changes: 5 additions & 1 deletion composer/src/main/kotlin/com/gojuno/composer/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner:
val installTimeout = Pair(args.installTimeoutSeconds, TimeUnit.SECONDS)
val installAppApk = device.installApk(pathToApk = args.appApkPath, timeout = installTimeout)
val installTestApk = device.installApk(pathToApk = args.testApkPath, timeout = installTimeout)
val installApks = mutableListOf(installAppApk, installTestApk)
installApks.addAll(args.extraApks.map {
device.installApk(pathToApk = it, timeout = installTimeout)
})

Observable
.concat(installAppApk, installTestApk)
.concat(installApks)
// Work with each device in parallel, but install apks sequentially on a device.
.subscribeOn(Schedulers.io())
.toList()
Expand Down
15 changes: 14 additions & 1 deletion composer/src/test/kotlin/com/gojuno/composer/ArgsSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ArgsSpec : Spek({
devicePattern = "",
installTimeoutSeconds = 120,
failIfNoTests = true,
runWithOrchestrator = false
runWithOrchestrator = false,
extraApks = emptyList()
))
}
}
Expand Down Expand Up @@ -205,4 +206,16 @@ class ArgsSpec : Spek({
assertThat(args.runWithOrchestrator).isEqualTo(true)
}
}

context("parse args with passed --extra-apks") {

val args by memoized {
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--extra-apks", "apk1.apk", "apk2.apk"))
}

it("parses correctly two extra apks") {
assertThat(args.extraApks).isEqualTo(listOf("apk1.apk", "apk2.apk"))
}
}

})

0 comments on commit 984b64f

Please sign in to comment.